Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

hwmon: (adc128d818) Do proper sign extension

data->temp[index] has type s16. Because of C's promotion rules,
(data->temp[index] << 7) >> 7 is exactly the same as
data->temp[index]. The intention was to use bit 8 as a sign bit, so do
that using the existing API.

Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>

authored by

Rasmus Villemoes and committed by
Guenter Roeck
2c3b1189 984faa1f

+2 -1
+2 -1
drivers/hwmon/adc128d818.c
··· 27 27 #include <linux/err.h> 28 28 #include <linux/regulator/consumer.h> 29 29 #include <linux/mutex.h> 30 + #include <linux/bitops.h> 30 31 31 32 /* Addresses to scan 32 33 * The chip also supports addresses 0x35..0x37. Don't scan those addresses ··· 190 189 if (IS_ERR(data)) 191 190 return PTR_ERR(data); 192 191 193 - temp = (data->temp[index] << 7) >> 7; /* sign extend */ 192 + temp = sign_extend32(data->temp[index], 8); 194 193 return sprintf(buf, "%d\n", temp * 500);/* 0.5 degrees C resolution */ 195 194 } 196 195