hwmon: (emc1403) Relax hysteresis limit write checks
authorGuenter Roeck <linux@roeck-us.net>
Mon, 12 May 2014 18:20:24 +0000 (11:20 -0700)
committerGuenter Roeck <linux@roeck-us.net>
Wed, 21 May 2014 23:02:24 +0000 (16:02 -0700)
Writing the hysteresis limit returned -ERANGE if the written hysteresis
was too high or too low. Relax error check and adjust the hysteresis
value to its valid range.

Reviewed-by: Jean Delvare <jdelvare@suse.de>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
drivers/hwmon/emc1403.c

index 46220b131153339f8b3e95b495041f797db32169..c62bc044a660778d439b4c495c5c88f6122964a3 100644 (file)
@@ -147,12 +147,7 @@ static ssize_t store_hyst(struct device *dev,
                goto fail;
 
        hyst = limit * 1000 - val;
-       hyst = DIV_ROUND_CLOSEST(hyst, 1000);
-       if (hyst < 0 || hyst > 255) {
-               retval = -ERANGE;
-               goto fail;
-       }
-
+       hyst = clamp_val(DIV_ROUND_CLOSEST(hyst, 1000), 0, 255);
        retval = regmap_write(regmap, 0x21, hyst);
        if (retval == 0)
                retval = count;