diff options
author | Guenter Roeck <linux@roeck-us.net> | 2014-07-06 11:39:24 -0700 |
---|---|---|
committer | Jiri Slaby <jslaby@suse.cz> | 2014-07-18 15:51:17 +0200 |
commit | 08efa418a9d5fdf12a383555e44d57280bff7fce (patch) | |
tree | 047106ef3bac4e013841b67ba3cbd8c6dfb5f329 /drivers/hwmon | |
parent | b57dd1ade2c2ba513ef03227548325dff760fbdf (diff) | |
download | linux-stable-08efa418a9d5fdf12a383555e44d57280bff7fce.tar.gz linux-stable-08efa418a9d5fdf12a383555e44d57280bff7fce.tar.bz2 linux-stable-08efa418a9d5fdf12a383555e44d57280bff7fce.zip |
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>
Signed-off-by: Jiri Slaby <jslaby@suse.cz>
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 2c137b26acb4..5790246a7e1d 100644 --- a/drivers/hwmon/emc2103.c +++ b/drivers/hwmon/emc2103.c @@ -250,9 +250,7 @@ static ssize_t set_temp_min(struct device *dev, struct device_attribute *da, if (result < 0) return result; - 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; @@ -274,9 +272,7 @@ static ssize_t set_temp_max(struct device *dev, struct device_attribute *da, if (result < 0) return result; - 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; @@ -390,15 +386,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 = kstrtol(buf, 10, &rpm_target); + int result = kstrtoul(buf, 10, &rpm_target); if (result < 0) return result; /* 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); |