Skip to content

Commit

Permalink
hwmon: (jc42) Fix integer overflow when writing hysteresis value
Browse files Browse the repository at this point in the history
Subtracting an unsigned long from a signed value causes an overflow with large
values. Use clamp_val() to reduce the number range prior to subtracting it
from the temperature limit.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Reviewed-by: Jean Delvare <jdelvare@suse.de>
  • Loading branch information
Guenter Roeck committed Jan 26, 2015
1 parent 3a05633 commit e2c26f0
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions drivers/hwmon/jc42.c
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,9 @@ static ssize_t set_temp_crit_hyst(struct device *dev,
if (kstrtoul(buf, 10, &val) < 0)
return -EINVAL;

val = clamp_val(val, 0, JC42_TEMP_MAX);
diff = jc42_temp_from_reg(data->temp[t_crit]) - val;

hyst = 0;
if (diff > 0) {
if (diff < 2250)
Expand Down

0 comments on commit e2c26f0

Please sign in to comment.