diff options
author | Guenter Roeck <linux@roeck-us.net> | 2014-07-06 11:39:24 -0700 |
---|---|---|
committer | Ben Hutchings <ben@decadent.org.uk> | 2014-08-06 18:07:36 +0100 |
commit | 831068ee2981914898798c1a7bd7988a2426b844 (patch) | |
tree | 9b5fc4ec6c6c5e5033bdfa8124897dfe5ba5df69 /drivers/hwmon | |
parent | 58b546648b5a5618db31ffaec70eb80b53a87d5b (diff) |
hwmon: (emc2103) Clamp limits instead of bailing out
commit f6c2dd20108c35e30e2c1f3c6142d189451a626b upstream.
It is customary to clamp limits instead of bailing out with an error
if a configured limit is out of the range supported by the driver.
This simplifies limit configuration, since the user will not typically
know chip and/or driver specific limits.
Reviewed-by: Jean Delvare <jdelvare@suse.de>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
[bwh: Backported to 3.2: adjust context]
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
Diffstat (limited to 'drivers/hwmon')
-rw-r--r-- | drivers/hwmon/emc2103.c | 15 |
1 files changed, 5 insertions, 10 deletions
diff --git a/drivers/hwmon/emc2103.c b/drivers/hwmon/emc2103.c index af914ad93ece..a074d21b39bb 100644 --- a/drivers/hwmon/emc2103.c +++ b/drivers/hwmon/emc2103.c @@ -248,9 +248,7 @@ static ssize_t set_temp_min(struct device *dev, struct device_attribute *da, if (result < 0) return -EINVAL; - val = DIV_ROUND_CLOSEST(val, 1000); - if ((val < -63) || (val > 127)) - return -EINVAL; + val = clamp_val(DIV_ROUND_CLOSEST(val, 1000), -63, 127); mutex_lock(&data->update_lock); data->temp_min[nr] = val; @@ -272,9 +270,7 @@ static ssize_t set_temp_max(struct device *dev, struct device_attribute *da, if (result < 0) return -EINVAL; - val = DIV_ROUND_CLOSEST(val, 1000); - if ((val < -63) || (val > 127)) - return -EINVAL; + val = clamp_val(DIV_ROUND_CLOSEST(val, 1000), -63, 127); mutex_lock(&data->update_lock); data->temp_max[nr] = val; @@ -386,15 +382,14 @@ static ssize_t set_fan_target(struct device *dev, struct device_attribute *da, { struct emc2103_data *data = emc2103_update_device(dev); struct i2c_client *client = to_i2c_client(dev); - long rpm_target; + unsigned long rpm_target; - int result = strict_strtol(buf, 10, &rpm_target); + int result = kstrtoul(buf, 10, &rpm_target); if (result < 0) return -EINVAL; /* Datasheet states 16384 as maximum RPM target (table 3.2) */ - if ((rpm_target < 0) || (rpm_target > 16384)) - return -EINVAL; + rpm_target = clamp_val(rpm_target, 0, 16384); mutex_lock(&data->update_lock); |