]> git.kernelconcepts.de Git - karo-tx-linux.git/commit
hwmon: (ad7314) Do proper sign extension
authorRasmus Villemoes <linux@rasmusvillemoes.dk>
Thu, 22 Jan 2015 22:44:13 +0000 (23:44 +0100)
committerGuenter Roeck <linux@roeck-us.net>
Mon, 26 Jan 2015 05:23:59 +0000 (21:23 -0800)
commit984faa1fb9175720828bf6604f936dff3f17b995
tree27815597043b4614d1a582840ae9b31f4bdd0020
parenta14c70729c46c740f37572879e8e7f3de43f6aa7
hwmon: (ad7314) Do proper sign extension

The comment above (data << 2) >> 2 explains what the intention is: To
use bit 13 of the 14-bit value data as the sign bit. However, this
doesn't work due to C's promotion rules. data has type s16, but data
<< 2 has type int. To get sign extension, that expression would have
to be cast back to an s16 before being shifted (at which point C's
promotion rules would then kick in again and promote the left operand
to int). As it stands, both expressions are no-ops for any value of
data.

Avoid these subtleties by using the existing API for
this. sign_extend32 works equally well for 8 and 16 bit types.

Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
drivers/hwmon/ad7314.c