diff options
author | Fabio Baltieri <fabio.baltieri@gmail.com> | 2014-06-08 22:06:24 +0100 |
---|---|---|
committer | Chanho Park <chanho61.park@samsung.com> | 2015-12-22 13:42:49 +0900 |
commit | c4e03aa31cae34dbdde2f0ff5ab678aa776417d9 (patch) | |
tree | 03f1dc8e31fd6880231452a8d25d10a67a9f377a /drivers/hwmon | |
parent | 56fad2a9dbb86d1609f2bb8c19e84f77f37d9cd3 (diff) | |
download | linux-3.10-artik-c4e03aa31cae34dbdde2f0ff5ab678aa776417d9.tar.gz linux-3.10-artik-c4e03aa31cae34dbdde2f0ff5ab678aa776417d9.tar.bz2 linux-3.10-artik-c4e03aa31cae34dbdde2f0ff5ab678aa776417d9.zip |
hwmon: (ina2xx) Cast to s16 on shunt and current regs
commit c0214f98943b1fe43f7be61b7782b0c8f0836f28 upstream.
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>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/hwmon')
-rw-r--r-- | drivers/hwmon/ina2xx.c | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/drivers/hwmon/ina2xx.c b/drivers/hwmon/ina2xx.c index 4958b2f89dc..371c1ee233b 100644 --- a/drivers/hwmon/ina2xx.c +++ b/drivers/hwmon/ina2xx.c @@ -147,7 +147,8 @@ static int ina2xx_get_value(struct ina2xx_data *data, u8 reg) switch (reg) { case INA2XX_SHUNT_VOLTAGE: - val = DIV_ROUND_CLOSEST(data->regs[reg], + /* signed register */ + val = DIV_ROUND_CLOSEST((s16)data->regs[reg], data->config->shunt_div); break; case INA2XX_BUS_VOLTAGE: @@ -159,8 +160,8 @@ static int ina2xx_get_value(struct ina2xx_data *data, u8 reg) val = data->regs[reg] * data->config->power_lsb; break; case INA2XX_CURRENT: - /* LSB=1mA (selected). Is in mA */ - val = data->regs[reg]; + /* signed register, LSB=1mA (selected), in mA */ + val = (s16)data->regs[reg]; break; default: /* programmer goofed */ |