Skip to content

Commit

Permalink
hwmon: (emc2103) Fix overflows seen when temperature limit attributes
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Guenter Roeck committed Dec 12, 2016
1 parent 67b2003 commit ca1b10b
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions drivers/hwmon/emc2103.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit ca1b10b

Please sign in to comment.