hwmon: (ds620) Fix overflows seen when writing temperature limits
authorGuenter Roeck <linux@roeck-us.net>
Sun, 20 Nov 2016 18:37:39 +0000 (10:37 -0800)
committerDanny Wood <danwood76@gmail.com>
Tue, 29 Jan 2019 13:15:49 +0000 (13:15 +0000)
commit e36ce99ee0815d7919a7b589bfb66f3de50b6bc7 upstream.

Module test reports:

temp1_max: Suspected overflow: [160000 vs. 0]
temp1_min: Suspected overflow: [160000 vs. 0]

This is seen because the values passed when writing temperature limits
are unbound.

Reviewed-by: Jean Delvare <jdelvare@suse.de>
Fixes: 6099469805c2 ("hwmon: Support for Dallas Semiconductor DS620")
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Willy Tarreau <w@1wt.eu>
drivers/hwmon/ds620.c

index f1d6b422cf0682b43ed6b4354481d97de240fcef..c25700f7db934261843499a92f5801e91af1a707 100644 (file)
@@ -166,7 +166,7 @@ static ssize_t set_temp(struct device *dev, struct device_attribute *da,
        if (res)
                return res;
 
-       val = (val * 10 / 625) * 8;
+       val = (clamp_val(val, -128000, 128000) * 10 / 625) * 8;
 
        mutex_lock(&data->update_lock);
        data->temp[attr->index] = val;