Skip to content

Commit

Permalink
hwmon: (adc128d818) Do proper sign extension
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Villemoes authored and groeck committed Jan 26, 2015
1 parent 984faa1 commit 2c3b118
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion drivers/hwmon/adc128d818.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <linux/err.h>
#include <linux/regulator/consumer.h>
#include <linux/mutex.h>
#include <linux/bitops.h>

/* Addresses to scan
* The chip also supports addresses 0x35..0x37. Don't scan those addresses
Expand Down Expand Up @@ -189,7 +190,7 @@ static ssize_t adc128_show_temp(struct device *dev,
if (IS_ERR(data))
return PTR_ERR(data);

temp = (data->temp[index] << 7) >> 7; /* sign extend */
temp = sign_extend32(data->temp[index], 8);
return sprintf(buf, "%d\n", temp * 500);/* 0.5 degrees C resolution */
}

Expand Down

0 comments on commit 2c3b118

Please sign in to comment.