]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
hwmon: (w83627ehf) Fix underflows seen when writing limit attributes
authorGuenter Roeck <linux@roeck-us.net>
Sun, 7 Jul 2024 06:51:34 +0000 (23:51 -0700)
committerGuenter Roeck <linux@roeck-us.net>
Sun, 7 Jul 2024 14:48:25 +0000 (07:48 -0700)
DIV_ROUND_CLOSEST() after kstrtol() results in an underflow if a large
negative number such as -9223372036854775808 is provided by the user.
Fix it by reordering clamp_val() and DIV_ROUND_CLOSEST() operations.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
drivers/hwmon/w83627ehf.c

index fe960c0a624f77e4c8ba49c03cb4311ebf2d5477..7d7d70afde65523d4e8fdf2cfd4b29f1f9616d88 100644 (file)
@@ -895,7 +895,7 @@ store_target_temp(struct device *dev, struct device_attribute *attr,
        if (err < 0)
                return err;
 
-       val = clamp_val(DIV_ROUND_CLOSEST(val, 1000), 0, 127);
+       val = DIV_ROUND_CLOSEST(clamp_val(val, 0, 127000), 1000);
 
        mutex_lock(&data->update_lock);
        data->target_temp[nr] = val;
@@ -920,7 +920,7 @@ store_tolerance(struct device *dev, struct device_attribute *attr,
                return err;
 
        /* Limit the temp to 0C - 15C */
-       val = clamp_val(DIV_ROUND_CLOSEST(val, 1000), 0, 15);
+       val = DIV_ROUND_CLOSEST(clamp_val(val, 0, 15000), 1000);
 
        mutex_lock(&data->update_lock);
        reg = w83627ehf_read_value(data, W83627EHF_REG_TOLERANCE[nr]);