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

hwmon: (adt7462) Fix overflows seen when writing into limit attributes

Fix overflows seen when writing large values into temperature limit,
voltage limit, and pwm hysteresis attributes.

The input parameter to DIV_ROUND_CLOSEST() needs to be clamped to avoid
such overflows.

Reviewed-by: Jean Delvare <jdelvare@suse.de>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>

+6 -6
+6 -6
drivers/hwmon/adt7462.c
··· 810 810 if (kstrtol(buf, 10, &temp) || !temp_enabled(data, attr->index)) 811 811 return -EINVAL; 812 812 813 + temp = clamp_val(temp, -64000, 191000); 813 814 temp = DIV_ROUND_CLOSEST(temp, 1000) + 64; 814 - temp = clamp_val(temp, 0, 255); 815 815 816 816 mutex_lock(&data->lock); 817 817 data->temp_min[attr->index] = temp; ··· 848 848 if (kstrtol(buf, 10, &temp) || !temp_enabled(data, attr->index)) 849 849 return -EINVAL; 850 850 851 + temp = clamp_val(temp, -64000, 191000); 851 852 temp = DIV_ROUND_CLOSEST(temp, 1000) + 64; 852 - temp = clamp_val(temp, 0, 255); 853 853 854 854 mutex_lock(&data->lock); 855 855 data->temp_max[attr->index] = temp; ··· 912 912 if (kstrtol(buf, 10, &temp) || !x) 913 913 return -EINVAL; 914 914 915 + temp = clamp_val(temp, 0, 255 * x / 1000); 915 916 temp *= 1000; /* convert mV to uV */ 916 917 temp = DIV_ROUND_CLOSEST(temp, x); 917 - temp = clamp_val(temp, 0, 255); 918 918 919 919 mutex_lock(&data->lock); 920 920 data->volt_max[attr->index] = temp; ··· 954 954 if (kstrtol(buf, 10, &temp) || !x) 955 955 return -EINVAL; 956 956 957 + temp = clamp_val(temp, 0, 255 * x / 1000); 957 958 temp *= 1000; /* convert mV to uV */ 958 959 temp = DIV_ROUND_CLOSEST(temp, x); 959 - temp = clamp_val(temp, 0, 255); 960 960 961 961 mutex_lock(&data->lock); 962 962 data->volt_min[attr->index] = temp; ··· 1220 1220 if (kstrtol(buf, 10, &temp)) 1221 1221 return -EINVAL; 1222 1222 1223 + temp = clamp_val(temp, 0, 15000); 1223 1224 temp = DIV_ROUND_CLOSEST(temp, 1000); 1224 - temp = clamp_val(temp, 0, 15); 1225 1225 1226 1226 /* package things up */ 1227 1227 temp &= ADT7462_PWM_HYST_MASK; ··· 1306 1306 if (kstrtol(buf, 10, &temp)) 1307 1307 return -EINVAL; 1308 1308 1309 + temp = clamp_val(temp, -64000, 191000); 1309 1310 temp = DIV_ROUND_CLOSEST(temp, 1000) + 64; 1310 - temp = clamp_val(temp, 0, 255); 1311 1311 1312 1312 mutex_lock(&data->lock); 1313 1313 data->pwm_tmin[attr->index] = temp;