aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon/ina2xx.c
diff options
context:
space:
mode:
authorFabio Baltieri <fabio.baltieri@gmail.com>2014-06-08 17:06:24 -0400
committerGuenter Roeck <linux@roeck-us.net>2014-06-12 11:36:18 -0400
commitc0214f98943b1fe43f7be61b7782b0c8f0836f28 (patch)
tree5a820dc1926e81b18ed357f94d3a1bbcb9d59d32 /drivers/hwmon/ina2xx.c
parent5c02c392cd2320e8d612376d6b72b6548a680923 (diff)
hwmon: (ina2xx) Cast to s16 on shunt and current regs
All devices supported by ina2xx are bidirectional and report the measured shunt voltage and power values as a signed 16 bit, but the current driver implementation caches all registers as u16, leading to an incorrect sign extension when reporting to userspace in ina2xx_get_value(). This patch fixes the problem by casting the signed registers to s16. Tested on an INA219. Signed-off-by: Fabio Baltieri <fabio.baltieri@gmail.com> Cc: stable@vger.kernel.org # 3.10+ Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Diffstat (limited to 'drivers/hwmon/ina2xx.c')
-rw-r--r--drivers/hwmon/ina2xx.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/drivers/hwmon/ina2xx.c b/drivers/hwmon/ina2xx.c
index 93d26e8af3e2..bfd3f3eeabcd 100644
--- a/drivers/hwmon/ina2xx.c
+++ b/drivers/hwmon/ina2xx.c
@@ -148,7 +148,8 @@ static int ina2xx_get_value(struct ina2xx_data *data, u8 reg)
148 148
149 switch (reg) { 149 switch (reg) {
150 case INA2XX_SHUNT_VOLTAGE: 150 case INA2XX_SHUNT_VOLTAGE:
151 val = DIV_ROUND_CLOSEST(data->regs[reg], 151 /* signed register */
152 val = DIV_ROUND_CLOSEST((s16)data->regs[reg],
152 data->config->shunt_div); 153 data->config->shunt_div);
153 break; 154 break;
154 case INA2XX_BUS_VOLTAGE: 155 case INA2XX_BUS_VOLTAGE:
@@ -160,8 +161,8 @@ static int ina2xx_get_value(struct ina2xx_data *data, u8 reg)
160 val = data->regs[reg] * data->config->power_lsb; 161 val = data->regs[reg] * data->config->power_lsb;
161 break; 162 break;
162 case INA2XX_CURRENT: 163 case INA2XX_CURRENT:
163 /* LSB=1mA (selected). Is in mA */ 164 /* signed register, LSB=1mA (selected), in mA */
164 val = data->regs[reg]; 165 val = (s16)data->regs[reg];
165 break; 166 break;
166 default: 167 default:
167 /* programmer goofed */ 168 /* programmer goofed */