]> git.karo-electronics.de Git - linux-beck.git/commitdiff
hwmon: (jc42) Fix integer overflow when writing hysteresis value
authorGuenter Roeck <linux@roeck-us.net>
Mon, 19 Jan 2015 17:16:53 +0000 (09:16 -0800)
committerGuenter Roeck <linux@roeck-us.net>
Mon, 26 Jan 2015 05:23:59 +0000 (21:23 -0800)
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>
drivers/hwmon/jc42.c

index f8e3bbbf019cf23b772300a6934bfe7942b398f1..a46cb65cacb50b00934eb404605d690af0758aca 100644 (file)
@@ -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)