]> git.baikalelectronics.ru Git - kernel.git/commit
powerpc/powernv: Fix sysparam sysfs error handling
authorJoel Stanley <joel@jms.id.au>
Thu, 24 Apr 2014 07:25:33 +0000 (16:55 +0930)
committerBenjamin Herrenschmidt <benh@kernel.crashing.org>
Mon, 28 Apr 2014 03:08:47 +0000 (13:08 +1000)
commit88ac622082eabbb51b0dbb9f028b4d3c9f3dd1bf
tree850f591bebcd208090d2db64329cd551c958f538
parentd8ffe9f33b715703f266386956a16b25a9d58d00
powerpc/powernv: Fix sysparam sysfs error handling

When a sysparam query in OPAL returned a negative value (error code),
sysfs would spew out a decent chunk of memory; almost 64K more than
expected. This was traced to a sign/unsigned mix up in the OPAL sysparam
sysfs code at sys_param_show.

The return value of sys_param_show is a ssize_t, calculated using

  return ret ? ret : attr->param_size;

Alan Modra explains:

  "attr->param_size" is an unsigned int, "ret" an int, so the overall
  expression has type unsigned int.  Result is that ret is cast to
  unsigned int before being cast to ssize_t.

Instead of using the ternary operator, set ret to the param_size if an
error is not detected. The same bug exists in the sysfs write callback;
this patch fixes it in the same way.

A note on debugging this next time: on my system gcc will warn about
this if compiled with -Wsign-compare, which is not enabled by -Wall,
only -Wextra.

Signed-off-by: Joel Stanley <joel@jms.id.au>
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
arch/powerpc/platforms/powernv/opal-sysparam.c