Skip to content

Commit af4d04b

Browse files
committed
hwmon: (amc6821) Stop accepting invalid pwm values
The pwm value range is well defined from 0..255. Don't accept any values outside this range. This changes the valid range of pwm1_auto_point2_pwm from 0..254 to 0..255, meaning it can now be equivalent to not only pwm1_auto_point1_pwm (which is always 0) but also to pwm1_auto_point3_pwm (which is always 255). While that may not be practical, there seems to be no technical reason for preventing a user from doing it. Reviewed-by: Quentin Schulz <[email protected]> Signed-off-by: Guenter Roeck <[email protected]>
1 parent 5c1de37 commit af4d04b

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

drivers/hwmon/amc6821.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -355,13 +355,13 @@ static ssize_t pwm1_store(struct device *dev,
355355
{
356356
struct amc6821_data *data = dev_get_drvdata(dev);
357357
struct i2c_client *client = data->client;
358-
long val;
359-
int ret = kstrtol(buf, 10, &val);
358+
u8 val;
359+
int ret = kstrtou8(buf, 10, &val);
360360
if (ret)
361361
return ret;
362362

363363
mutex_lock(&data->update_lock);
364-
data->pwm1 = clamp_val(val , 0, 255);
364+
data->pwm1 = val;
365365
i2c_smbus_write_byte_data(client, AMC6821_REG_DCY, data->pwm1);
366366
mutex_unlock(&data->update_lock);
367367
return count;
@@ -558,13 +558,15 @@ static ssize_t pwm1_auto_point_pwm_store(struct device *dev,
558558
struct amc6821_data *data = dev_get_drvdata(dev);
559559
struct i2c_client *client = data->client;
560560
int dpwm;
561-
long val;
562-
int ret = kstrtol(buf, 10, &val);
561+
u8 val;
562+
int ret;
563+
564+
ret = kstrtou8(buf, 10, &val);
563565
if (ret)
564566
return ret;
565567

566568
mutex_lock(&data->update_lock);
567-
data->pwm1_auto_point_pwm[1] = clamp_val(val, 0, 254);
569+
data->pwm1_auto_point_pwm[1] = val;
568570
if (i2c_smbus_write_byte_data(client, AMC6821_REG_DCY_LOW_TEMP,
569571
data->pwm1_auto_point_pwm[1])) {
570572
dev_err(&client->dev, "Register write error, aborting.\n");

0 commit comments

Comments
 (0)