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

hwmon: (w83627ehf) Fix underflows seen when writing limit attributes

DIV_ROUND_CLOSEST() after kstrtol() results in an underflow if a large
negative number such as -9223372036854775808 is provided by the user.
Fix it by reordering clamp_val() and DIV_ROUND_CLOSEST() operations.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>

+2 -2
+2 -2
drivers/hwmon/w83627ehf.c
··· 895 895 if (err < 0) 896 896 return err; 897 897 898 - val = clamp_val(DIV_ROUND_CLOSEST(val, 1000), 0, 127); 898 + val = DIV_ROUND_CLOSEST(clamp_val(val, 0, 127000), 1000); 899 899 900 900 mutex_lock(&data->update_lock); 901 901 data->target_temp[nr] = val; ··· 920 920 return err; 921 921 922 922 /* Limit the temp to 0C - 15C */ 923 - val = clamp_val(DIV_ROUND_CLOSEST(val, 1000), 0, 15); 923 + val = DIV_ROUND_CLOSEST(clamp_val(val, 0, 15000), 1000); 924 924 925 925 mutex_lock(&data->update_lock); 926 926 reg = w83627ehf_read_value(data, W83627EHF_REG_TOLERANCE[nr]);