From: Guenter Roeck Date: Mon, 5 Dec 2016 02:19:51 +0000 (-0800) Subject: hwmon: (emc2103) Fix overflows seen when temperature limit attributes X-Git-Url: https://git.karo-electronics.de/?a=commitdiff_plain;h=ca1b10b8250247fb5f241d1cb894c102203378bb;p=linux-beck.git hwmon: (emc2103) Fix overflows seen when temperature limit attributes Writes into temperature limit attributes can overflow due to unbound values passed to DIV_ROUND_CLOSEST(). Cc: Steve Glendinning Reviewed-by: Jean Delvare Signed-off-by: Guenter Roeck --- diff --git a/drivers/hwmon/emc2103.c b/drivers/hwmon/emc2103.c index 24e395c5907d..4b870ee9b0d3 100644 --- a/drivers/hwmon/emc2103.c +++ b/drivers/hwmon/emc2103.c @@ -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;