Commit 539a719f authored by Guenter Roeck's avatar Guenter Roeck

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 plain divide operation
to reduce the rounding error when writing temperature limits.
Signed-off-by: default avatarGuenter Roeck <linux@roeck-us.net>
Reviewed-by: default avatarJean Delvare <jdelvare@suse.de>
parent e9814295
...@@ -252,12 +252,12 @@ static ssize_t set_temp(struct device *dev, struct device_attribute *devattr, ...@@ -252,12 +252,12 @@ static ssize_t set_temp(struct device *dev, struct device_attribute *devattr,
if (err < 0) if (err < 0)
return err; return err;
val /= 1000; val = DIV_ROUND_CLOSEST(val, 1000);
reg = (sf == min) ? EMC6W201_REG_TEMP_LOW(nr) reg = (sf == min) ? EMC6W201_REG_TEMP_LOW(nr)
: EMC6W201_REG_TEMP_HIGH(nr); : EMC6W201_REG_TEMP_HIGH(nr);
mutex_lock(&data->update_lock); 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]); err = emc6w201_write8(client, reg, data->temp[sf][nr]);
mutex_unlock(&data->update_lock); mutex_unlock(&data->update_lock);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment