]> git.karo-electronics.de Git - linux-beck.git/commitdiff
hwmon: (emc2103) Fix overflows seen when temperature limit attributes
authorGuenter Roeck <linux@roeck-us.net>
Mon, 5 Dec 2016 02:19:51 +0000 (18:19 -0800)
committerGuenter Roeck <linux@roeck-us.net>
Mon, 12 Dec 2016 19:33:43 +0000 (11:33 -0800)
Writes into temperature limit attributes can overflow due to unbound
values passed to DIV_ROUND_CLOSEST().

Cc: Steve Glendinning <steve.glendinning@shawell.net>
Reviewed-by: Jean Delvare <jdelvare@suse.de>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
drivers/hwmon/emc2103.c

index 24e395c5907d4c549912072c3219bd24c389488e..4b870ee9b0d3d934748632d4d33309f05d0d5983 100644 (file)
@@ -251,7 +251,7 @@ static ssize_t set_temp_min(struct device *dev, struct device_attribute *da,
        if (result < 0)
                return result;
 
-       val = clamp_val(DIV_ROUND_CLOSEST(val, 1000), -63, 127);
+       val = DIV_ROUND_CLOSEST(clamp_val(val, -63000, 127000), 1000);
 
        mutex_lock(&data->update_lock);
        data->temp_min[nr] = val;
@@ -273,7 +273,7 @@ static ssize_t set_temp_max(struct device *dev, struct device_attribute *da,
        if (result < 0)
                return result;
 
-       val = clamp_val(DIV_ROUND_CLOSEST(val, 1000), -63, 127);
+       val = DIV_ROUND_CLOSEST(clamp_val(val, -63000, 127000), 1000);
 
        mutex_lock(&data->update_lock);
        data->temp_max[nr] = val;