aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon/emc2103.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/hwmon/emc2103.c')
-rw-r--r--drivers/hwmon/emc2103.c15
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