Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: Guenter Roeck <linux@roeck-us.net>
Reviewed-by: Jean Delvare <jdelvare@suse.de>

+2 -2
+2 -2
drivers/hwmon/emc6w201.c
··· 252 252 if (err < 0) 253 253 return err; 254 254 255 - val /= 1000; 255 + val = DIV_ROUND_CLOSEST(val, 1000); 256 256 reg = (sf == min) ? EMC6W201_REG_TEMP_LOW(nr) 257 257 : EMC6W201_REG_TEMP_HIGH(nr); 258 258 259 259 mutex_lock(&data->update_lock); 260 - data->temp[sf][nr] = clamp_val(val, -127, 128); 260 + data->temp[sf][nr] = clamp_val(val, -127, 127); 261 261 err = emc6w201_write8(client, reg, data->temp[sf][nr]); 262 262 mutex_unlock(&data->update_lock); 263 263