summaryrefslogtreecommitdiffstats
path: root/drivers/hwmon/ina2xx.c
diff options
context:
space:
mode:
authorBartosz Golaszewski <bgolaszewski@baylibre.com>2015-01-12 14:47:22 +0100
committerGuenter Roeck <linux@roeck-us.net>2015-01-26 06:23:59 +0100
commitb721fe2a3a92b896ba1b41e338471dfef672052a (patch)
treed982f8763a82b764cbe2d62308f7a6a11e4c73f3 /drivers/hwmon/ina2xx.c
parenthwmon: (ina2xx) remove an unnecessary dev_get_drvdata() result check (diff)
downloadlinux-b721fe2a3a92b896ba1b41e338471dfef672052a.tar.xz
linux-b721fe2a3a92b896ba1b41e338471dfef672052a.zip
hwmon: (ina2xx) use DIV_ROUND_CLOSEST() to avoid rounding errors
Use DIV_ROUND_CLOSEST() when dealing with the calibration values to make the calculations less error prone. Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Diffstat (limited to '')
-rw-r--r--drivers/hwmon/ina2xx.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/drivers/hwmon/ina2xx.c b/drivers/hwmon/ina2xx.c
index ae110c5386ae..611ec4edd979 100644
--- a/drivers/hwmon/ina2xx.c
+++ b/drivers/hwmon/ina2xx.c
@@ -186,8 +186,11 @@ static void ina226_set_update_interval(struct ina2xx_data *data)
static int ina2xx_calibrate(struct ina2xx_data *data)
{
- return i2c_smbus_write_word_swapped(data->client, INA2XX_CALIBRATION,
- data->config->calibration_factor / data->rshunt);
+ u16 val = DIV_ROUND_CLOSEST(data->config->calibration_factor,
+ data->rshunt);
+
+ return i2c_smbus_write_word_swapped(data->client,
+ INA2XX_CALIBRATION, val);
}
/*
@@ -307,7 +310,8 @@ static int ina2xx_get_value(struct ina2xx_data *data, u8 reg)
val = (s16)data->regs[reg];
break;
case INA2XX_CALIBRATION:
- val = data->config->calibration_factor / data->regs[reg];
+ val = DIV_ROUND_CLOSEST(data->config->calibration_factor,
+ data->regs[reg]);
break;
default:
/* programmer goofed */