]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/commitdiff
hwmon: (adt7470) Fix overflows seen when writing into limit attributes
authorGuenter Roeck <linux@roeck-us.net>
Sat, 3 Dec 2016 19:10:34 +0000 (11:10 -0800)
committerGuenter Roeck <linux@roeck-us.net>
Sat, 10 Dec 2016 05:54:32 +0000 (21:54 -0800)
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>
drivers/hwmon/adt7470.c

index 6e60ca53406e7fce4f581432f6e81296b7b36cd1..c9a1d9c25572a466dab697a01e9b7c2a00808702 100644 (file)
@@ -483,8 +483,8 @@ static ssize_t set_temp_min(struct device *dev,
        if (kstrtol(buf, 10, &temp))
                return -EINVAL;
 
+       temp = clamp_val(temp, -128000, 127000);
        temp = DIV_ROUND_CLOSEST(temp, 1000);
-       temp = clamp_val(temp, -128, 127);
 
        mutex_lock(&data->lock);
        data->temp_min[attr->index] = temp;
@@ -517,8 +517,8 @@ static ssize_t set_temp_max(struct device *dev,
        if (kstrtol(buf, 10, &temp))
                return -EINVAL;
 
+       temp = clamp_val(temp, -128000, 127000);
        temp = DIV_ROUND_CLOSEST(temp, 1000);
-       temp = clamp_val(temp, -128, 127);
 
        mutex_lock(&data->lock);
        data->temp_max[attr->index] = temp;
@@ -880,8 +880,8 @@ static ssize_t set_pwm_tmin(struct device *dev,
        if (kstrtol(buf, 10, &temp))
                return -EINVAL;
 
+       temp = clamp_val(temp, -128000, 127000);
        temp = DIV_ROUND_CLOSEST(temp, 1000);
-       temp = clamp_val(temp, -128, 127);
 
        mutex_lock(&data->lock);
        data->pwm_tmin[attr->index] = temp;