Skip to contentSkip to conversation

hwmon: (ina2xx) code clean-up and minor fixes

PATCH In review Bartosz Golaszewski 2 participants 4 messages Jan 12, 2015 Hardware monitoring

lore
Share & tools
lore
#0 lore raw

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
#1 lore raw

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
index a16d6a2..ae110c5 100644
@@ -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
#2 lore raw

PATCH 2/2 hwmon: (ina2xx) use DIV_ROUND_CLOSEST() to avoid rounding errors

In reply to Bartosz Golaszewski

Use 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
index ae110c5..611ec4e 100644
@@ -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
maintainer
#3 lore raw
In reply to Bartosz Golaszewski
Quoted 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 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

Both applied to -next.

Thanks,
Guenter

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors