mirror of
https://github.com/torvalds/linux.git
synced 2024-09-25 01:13:04 +00:00
hwmon: (adt7470) Fix overflows seen when writing into limit attributes
Fix overflows seen when writing large values into various temperature limit attributes. The input value passed 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>
This commit is contained in:
parent
b94793b4da
commit
64bd708ae0
|
@ -483,8 +483,8 @@ static ssize_t set_temp_min(struct device *dev,
|
||||||
if (kstrtol(buf, 10, &temp))
|
if (kstrtol(buf, 10, &temp))
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
|
temp = clamp_val(temp, -128000, 127000);
|
||||||
temp = DIV_ROUND_CLOSEST(temp, 1000);
|
temp = DIV_ROUND_CLOSEST(temp, 1000);
|
||||||
temp = clamp_val(temp, -128, 127);
|
|
||||||
|
|
||||||
mutex_lock(&data->lock);
|
mutex_lock(&data->lock);
|
||||||
data->temp_min[attr->index] = temp;
|
data->temp_min[attr->index] = temp;
|
||||||
|
@ -517,8 +517,8 @@ static ssize_t set_temp_max(struct device *dev,
|
||||||
if (kstrtol(buf, 10, &temp))
|
if (kstrtol(buf, 10, &temp))
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
|
temp = clamp_val(temp, -128000, 127000);
|
||||||
temp = DIV_ROUND_CLOSEST(temp, 1000);
|
temp = DIV_ROUND_CLOSEST(temp, 1000);
|
||||||
temp = clamp_val(temp, -128, 127);
|
|
||||||
|
|
||||||
mutex_lock(&data->lock);
|
mutex_lock(&data->lock);
|
||||||
data->temp_max[attr->index] = temp;
|
data->temp_max[attr->index] = temp;
|
||||||
|
@ -880,8 +880,8 @@ static ssize_t set_pwm_tmin(struct device *dev,
|
||||||
if (kstrtol(buf, 10, &temp))
|
if (kstrtol(buf, 10, &temp))
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
|
temp = clamp_val(temp, -128000, 127000);
|
||||||
temp = DIV_ROUND_CLOSEST(temp, 1000);
|
temp = DIV_ROUND_CLOSEST(temp, 1000);
|
||||||
temp = clamp_val(temp, -128, 127);
|
|
||||||
|
|
||||||
mutex_lock(&data->lock);
|
mutex_lock(&data->lock);
|
||||||
data->pwm_tmin[attr->index] = temp;
|
data->pwm_tmin[attr->index] = temp;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user