hwmon: (ina2xx) code clean-up and minor fixes
cover hwmon: (ina2xx) code clean-up and minor fixes
This small series fixes two minor issues in the driver after recent implementation of new attributes. The first patch removes an unnecessary result check after calling dev_get_drvdata() and the second one adds calls to DIV_ROUND_CLOSEST() to avoid rounding errors.
This series is rebased against current hwmon-next.
Bartosz Golaszewski (2):
hwmon: (ina2xx) remove an unnecessary dev_get_drvdata() result check
hwmon: (ina2xx) use DIV_ROUND_CLOSEST() to avoid rounding errors
drivers/hwmon/ina2xx.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)
Signature · 7 lines
2.1.3 _______________________________________________ lm-sensors mailing list [email protected] http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
PATCH 1/2 hwmon: (ina2xx) remove an unnecessary dev_get_drvdata() result check
--- drivers/hwmon/ina2xx.c | 3 --- 1 file changed, 3 deletions(-)
drivers/hwmon/ina2xx.c +0 -3
@@ -370,9 +370,6 @@ static ssize_t ina226_set_interval(struct device *dev,unsigned long val;int status; -if (IS_ERR (data)) -return PTR_ERR (data); - status =kstrtoul (buf,10 , &val);if (status <0 )return status;
Signature · 7 lines
2.1.3 _______________________________________________ lm-sensors mailing list [email protected] http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
PATCH 2/2 hwmon: (ina2xx) use DIV_ROUND_CLOSEST() to avoid rounding errors
In reply to Bartosz GolaszewskiUse DIV_ROUND_CLOSEST() when dealing with the calibration values to make the calculations less error prone.
--- drivers/hwmon/ina2xx.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
drivers/hwmon/ina2xx.c +7 -3
@@ -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 */
Signature · 7 lines
2.1.3 _______________________________________________ lm-sensors mailing list [email protected] http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
Guenter Roeck
maintainerQuoted 11 lines · Bartosz Golaszewski
This small series fixes two minor issues in the driver after recent implementation of new attributes. The first patch removes an unnecessary result check after calling
dev_get_drvdata()and the second one adds calls toDIV_ROUND_CLOSEST()to avoid rounding errors.This series is rebased against current hwmon-next.
Bartosz Golaszewski (2):
hwmon: (ina2xx) remove an unnecessarydev_get_drvdata()result check
hwmon: (ina2xx) useDIV_ROUND_CLOSEST()to avoid rounding errors
Both applied to -next.
Thanks,
Guenter
_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors