Skip to contentSkip to conversation

hwmon: (emc6w201) Fix temperature limit range

PATCH In review Guenter Roeck 2 participants 2 messages Aug 5, 2014 Hardware monitoring

lore
Share & tools
lore

Guenter Roeck

author maintainer
#0 lore raw

PATCH v2 1/1 hwmon: (emc6w201) Fix temperature limit range

Temperature limit range is [-127, 127], not [-127, 128]. The wrong range caused a bad limit to be written into the chip if the limit was set to a value of 128 degrees C or above.

Also use DIV_ROUND_CLOSEST instead of a plan divide operation to reduce the rounding error when writing temperature limits.

---
v2: Correct temperature range is [-127, 127]; -128 indicates an error.

 drivers/hwmon/emc6w201.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/hwmon/emc6w201.c +2 -2
index e87da90..ada9071 100644
@@ -252,12 +252,12 @@ static ssize_t set_temp(struct device *dev, struct device_attribute *devattr,
 	if (err < 0)
 		return err;
 
-	val /= 1000;
+	val = DIV_ROUND_CLOSEST(val, 1000);
 	reg = (sf = min) ? EMC6W201_REG_TEMP_LOW(nr)
 			  : EMC6W201_REG_TEMP_HIGH(nr);
 
 	mutex_lock(&data->update_lock);
-	data->temp[sf][nr] = clamp_val(val, -127, 128);
+	data->temp[sf][nr] = clamp_val(val, -127, 127);
 	err = emc6w201_write8(client, reg, data->temp[sf][nr]);
 	mutex_unlock(&data->update_lock);
 
Signature · 7 lines
1.9.1


_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
Reviewed-by on v2 1/1
#1 lore raw
Quoted 23 lines · Guenter Roeck

Temperature limit range is [-127, 127], not [-127, 128]. The wrong range caused a bad limit to be written into the chip if the limit was set to a value of 128 degrees C or above.

Also use DIV_ROUND_CLOSEST instead of a plan divide operation to reduce the rounding error when writing temperature limits.

---
v2: Correct temperature range is [-127, 127]; -128 indicates an error.

 drivers/hwmon/emc6w201.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/hwmon/emc6w201.c +0 -1
index e87da90..ada9071 100644
@@ -252,12 +252,12 @@ static ssize_t set_temp(struct device *dev, struct device_attribute *devattr,
 	if (err < 0)
 		return err;
 
-	val /= 1000;

drivers/hwmon/emc6w201.c static ssize_t set_temp(struct device *dev, struct device_attribute *devattr, · line 263

Quoted 10 lines
drivers/hwmon/emc6w201.c +2 -1
+	val = DIV_ROUND_CLOSEST(val, 1000);
 	reg = (sf = min) ? EMC6W201_REG_TEMP_LOW(nr)
 			  : EMC6W201_REG_TEMP_HIGH(nr);
 
 	mutex_lock(&data->update_lock);
-	data->temp[sf][nr] = clamp_val(val, -127, 128);
+	data->temp[sf][nr] = clamp_val(val, -127, 127);
 	err = emc6w201_write8(client, reg, data->temp[sf][nr]);
 	mutex_unlock(&data->update_lock);
 
Signature · 7 lines
Jean Delvare
SUSE L3 Support

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