Commit 831068ee authored by Guenter Roeck's avatar Guenter Roeck Committed by Ben Hutchings

hwmon: (emc2103) Clamp limits instead of bailing out

commit f6c2dd20 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: default avatarJean Delvare <jdelvare@suse.de>
Signed-off-by: default avatarGuenter Roeck <linux@roeck-us.net>
[bwh: Backported to 3.2: adjust context]
Signed-off-by: default avatarBen Hutchings <ben@decadent.org.uk>
parent 58b54664
...@@ -248,9 +248,7 @@ static ssize_t set_temp_min(struct device *dev, struct device_attribute *da, ...@@ -248,9 +248,7 @@ static ssize_t set_temp_min(struct device *dev, struct device_attribute *da,
if (result < 0) if (result < 0)
return -EINVAL; return -EINVAL;
val = DIV_ROUND_CLOSEST(val, 1000); val = clamp_val(DIV_ROUND_CLOSEST(val, 1000), -63, 127);
if ((val < -63) || (val > 127))
return -EINVAL;
mutex_lock(&data->update_lock); mutex_lock(&data->update_lock);
data->temp_min[nr] = val; data->temp_min[nr] = val;
...@@ -272,9 +270,7 @@ static ssize_t set_temp_max(struct device *dev, struct device_attribute *da, ...@@ -272,9 +270,7 @@ static ssize_t set_temp_max(struct device *dev, struct device_attribute *da,
if (result < 0) if (result < 0)
return -EINVAL; return -EINVAL;
val = DIV_ROUND_CLOSEST(val, 1000); val = clamp_val(DIV_ROUND_CLOSEST(val, 1000), -63, 127);
if ((val < -63) || (val > 127))
return -EINVAL;
mutex_lock(&data->update_lock); mutex_lock(&data->update_lock);
data->temp_max[nr] = val; data->temp_max[nr] = val;
...@@ -386,15 +382,14 @@ static ssize_t set_fan_target(struct device *dev, struct device_attribute *da, ...@@ -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 emc2103_data *data = emc2103_update_device(dev);
struct i2c_client *client = to_i2c_client(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) if (result < 0)
return -EINVAL; return -EINVAL;
/* Datasheet states 16384 as maximum RPM target (table 3.2) */ /* Datasheet states 16384 as maximum RPM target (table 3.2) */
if ((rpm_target < 0) || (rpm_target > 16384)) rpm_target = clamp_val(rpm_target, 0, 16384);
return -EINVAL;
mutex_lock(&data->update_lock); mutex_lock(&data->update_lock);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment