Commit f27ec1d6 authored by Roland Dreier's avatar Roland Dreier

IB/qib: Don't rely on (undefined) order of function parameter evaluation

Some of the qib sysfs code passes a buffer pointer into 
simple_read_from_buffer() but relies on a function call in another 
parameter of the same call to initialize that pointer.  Since the order
of evaluation of function parameters is undefined, this will break if
gcc chooses the wrong order.

Fix this by splitting the code into two separate function calls.

This was noticed because of warnings like the following on ppc:

    drivers/infiniband/hw/qib/qib_fs.c: In function 'portcntrs_2_read':
    drivers/infiniband/hw/qib/qib_fs.c:203: warning: 'counters' is used uninitialized in this function
Reported-by: default avatarStephen Rothwell <sfr@canb.auug.org.au>
Signed-off-by: default avatarRoland Dreier <rolandd@cisco.com>
parent 7e3a1f4a
...@@ -144,10 +144,11 @@ static ssize_t dev_counters_read(struct file *file, char __user *buf, ...@@ -144,10 +144,11 @@ static ssize_t dev_counters_read(struct file *file, char __user *buf,
size_t count, loff_t *ppos) size_t count, loff_t *ppos)
{ {
u64 *counters; u64 *counters;
size_t avail;
struct qib_devdata *dd = private2dd(file); struct qib_devdata *dd = private2dd(file);
return simple_read_from_buffer(buf, count, ppos, counters, avail = dd->f_read_cntrs(dd, *ppos, NULL, &counters);
dd->f_read_cntrs(dd, *ppos, NULL, &counters)); return simple_read_from_buffer(buf, count, ppos, counters, avail);
} }
/* read the per-device counters */ /* read the per-device counters */
...@@ -155,10 +156,11 @@ static ssize_t dev_names_read(struct file *file, char __user *buf, ...@@ -155,10 +156,11 @@ static ssize_t dev_names_read(struct file *file, char __user *buf,
size_t count, loff_t *ppos) size_t count, loff_t *ppos)
{ {
char *names; char *names;
size_t avail;
struct qib_devdata *dd = private2dd(file); struct qib_devdata *dd = private2dd(file);
return simple_read_from_buffer(buf, count, ppos, names, avail = dd->f_read_cntrs(dd, *ppos, &names, NULL);
dd->f_read_cntrs(dd, *ppos, &names, NULL)); return simple_read_from_buffer(buf, count, ppos, names, avail);
} }
static const struct file_operations cntr_ops[] = { static const struct file_operations cntr_ops[] = {
...@@ -176,10 +178,11 @@ static ssize_t portnames_read(struct file *file, char __user *buf, ...@@ -176,10 +178,11 @@ static ssize_t portnames_read(struct file *file, char __user *buf,
size_t count, loff_t *ppos) size_t count, loff_t *ppos)
{ {
char *names; char *names;
size_t avail;
struct qib_devdata *dd = private2dd(file); struct qib_devdata *dd = private2dd(file);
return simple_read_from_buffer(buf, count, ppos, names, avail = dd->f_read_portcntrs(dd, *ppos, 0, &names, NULL);
dd->f_read_portcntrs(dd, *ppos, 0, &names, NULL)); return simple_read_from_buffer(buf, count, ppos, names, avail);
} }
/* read the per-port counters for port 1 (pidx 0) */ /* read the per-port counters for port 1 (pidx 0) */
...@@ -187,10 +190,11 @@ static ssize_t portcntrs_1_read(struct file *file, char __user *buf, ...@@ -187,10 +190,11 @@ static ssize_t portcntrs_1_read(struct file *file, char __user *buf,
size_t count, loff_t *ppos) size_t count, loff_t *ppos)
{ {
u64 *counters; u64 *counters;
size_t avail;
struct qib_devdata *dd = private2dd(file); struct qib_devdata *dd = private2dd(file);
return simple_read_from_buffer(buf, count, ppos, counters, avail = dd->f_read_portcntrs(dd, *ppos, 0, NULL, &counters);
dd->f_read_portcntrs(dd, *ppos, 0, NULL, &counters)); return simple_read_from_buffer(buf, count, ppos, counters, avail);
} }
/* read the per-port counters for port 2 (pidx 1) */ /* read the per-port counters for port 2 (pidx 1) */
...@@ -198,10 +202,11 @@ static ssize_t portcntrs_2_read(struct file *file, char __user *buf, ...@@ -198,10 +202,11 @@ static ssize_t portcntrs_2_read(struct file *file, char __user *buf,
size_t count, loff_t *ppos) size_t count, loff_t *ppos)
{ {
u64 *counters; u64 *counters;
size_t avail;
struct qib_devdata *dd = private2dd(file); struct qib_devdata *dd = private2dd(file);
return simple_read_from_buffer(buf, count, ppos, counters, avail = dd->f_read_portcntrs(dd, *ppos, 1, NULL, &counters);
dd->f_read_portcntrs(dd, *ppos, 1, NULL, &counters)); return simple_read_from_buffer(buf, count, ppos, counters, avail);
} }
static const struct file_operations portcntr_ops[] = { static const struct file_operations portcntr_ops[] = {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment