diff options
| author | Guenter Roeck <linux@roeck-us.net> | 2014-07-06 14:39:24 -0400 |
|---|---|---|
| committer | Guenter Roeck <linux@roeck-us.net> | 2014-07-07 10:15:31 -0400 |
| commit | f6c2dd20108c35e30e2c1f3c6142d189451a626b (patch) | |
| tree | 85f480798ada89cfdc556c3863b653902eaae725 | |
| parent | 145e74a4e5022225adb84f4e5d4fff7938475c35 (diff) | |
hwmon: (emc2103) Clamp limits instead of bailing out
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>
Cc: stable@vger.kernel.org
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
| -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 fd892dd48e4c..78002de46cb6 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, | |||
| 250 | if (result < 0) | 250 | if (result < 0) |
| 251 | return result; | 251 | return result; |
| 252 | 252 | ||
| 253 | val = DIV_ROUND_CLOSEST(val, 1000); | 253 | val = clamp_val(DIV_ROUND_CLOSEST(val, 1000), -63, 127); |
| 254 | if ((val < -63) || (val > 127)) | ||
| 255 | return -EINVAL; | ||
| 256 | 254 | ||
| 257 | mutex_lock(&data->update_lock); | 255 | mutex_lock(&data->update_lock); |
| 258 | data->temp_min[nr] = val; | 256 | data->temp_min[nr] = val; |
| @@ -274,9 +272,7 @@ static ssize_t set_temp_max(struct device *dev, struct device_attribute *da, | |||
| 274 | if (result < 0) | 272 | if (result < 0) |
| 275 | return result; | 273 | return result; |
| 276 | 274 | ||
| 277 | val = DIV_ROUND_CLOSEST(val, 1000); | 275 | val = clamp_val(DIV_ROUND_CLOSEST(val, 1000), -63, 127); |
| 278 | if ((val < -63) || (val > 127)) | ||
| 279 | return -EINVAL; | ||
| 280 | 276 | ||
| 281 | mutex_lock(&data->update_lock); | 277 | mutex_lock(&data->update_lock); |
| 282 | data->temp_max[nr] = val; | 278 | data->temp_max[nr] = val; |
| @@ -390,15 +386,14 @@ static ssize_t set_fan_target(struct device *dev, struct device_attribute *da, | |||
| 390 | { | 386 | { |
| 391 | struct emc2103_data *data = emc2103_update_device(dev); | 387 | struct emc2103_data *data = emc2103_update_device(dev); |
| 392 | struct i2c_client *client = to_i2c_client(dev); | 388 | struct i2c_client *client = to_i2c_client(dev); |
| 393 | long rpm_target; | 389 | unsigned long rpm_target; |
| 394 | 390 | ||
| 395 | int result = kstrtol(buf, 10, &rpm_target); | 391 | int result = kstrtoul(buf, 10, &rpm_target); |
| 396 | if (result < 0) | 392 | if (result < 0) |
| 397 | return result; | 393 | return result; |
| 398 | 394 | ||
| 399 | /* Datasheet states 16384 as maximum RPM target (table 3.2) */ | 395 | /* Datasheet states 16384 as maximum RPM target (table 3.2) */ |
| 400 | if ((rpm_target < 0) || (rpm_target > 16384)) | 396 | rpm_target = clamp_val(rpm_target, 0, 16384); |
| 401 | return -EINVAL; | ||
| 402 | 397 | ||
| 403 | mutex_lock(&data->update_lock); | 398 | mutex_lock(&data->update_lock); |
| 404 | 399 | ||
