summaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorGuenter Roeck <linux@roeck-us.net>2024-06-27 02:21:54 +0200
committerGuenter Roeck <linux@roeck-us.net>2024-07-08 16:52:36 +0200
commitaf4d04b8ce08a734889fb0777059063635242614 (patch)
tree8e49b82eacef331972fe71c6506bee0c455fefc7 /drivers
parenthwmon: (w83627ehf) Fix underflows seen when writing limit attributes (diff)
downloadlinux-af4d04b8ce08a734889fb0777059063635242614.tar.xz
linux-af4d04b8ce08a734889fb0777059063635242614.zip
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 <quentin.schulz@cherry.de> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/hwmon/amc6821.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/drivers/hwmon/amc6821.c b/drivers/hwmon/amc6821.c
index 9b02b304c2f5..dc35e9b21f91 100644
--- a/drivers/hwmon/amc6821.c
+++ b/drivers/hwmon/amc6821.c
@@ -355,13 +355,13 @@ static ssize_t pwm1_store(struct device *dev,
{
struct amc6821_data *data = dev_get_drvdata(dev);
struct i2c_client *client = data->client;
- long val;
- int ret = kstrtol(buf, 10, &val);
+ u8 val;
+ int ret = kstrtou8(buf, 10, &val);
if (ret)
return ret;
mutex_lock(&data->update_lock);
- data->pwm1 = clamp_val(val , 0, 255);
+ data->pwm1 = val;
i2c_smbus_write_byte_data(client, AMC6821_REG_DCY, data->pwm1);
mutex_unlock(&data->update_lock);
return count;
@@ -558,13 +558,15 @@ static ssize_t pwm1_auto_point_pwm_store(struct device *dev,
struct amc6821_data *data = dev_get_drvdata(dev);
struct i2c_client *client = data->client;
int dpwm;
- long val;
- int ret = kstrtol(buf, 10, &val);
+ u8 val;
+ int ret;
+
+ ret = kstrtou8(buf, 10, &val);
if (ret)
return ret;
mutex_lock(&data->update_lock);
- data->pwm1_auto_point_pwm[1] = clamp_val(val, 0, 254);
+ data->pwm1_auto_point_pwm[1] = val;
if (i2c_smbus_write_byte_data(client, AMC6821_REG_DCY_LOW_TEMP,
data->pwm1_auto_point_pwm[1])) {
dev_err(&client->dev, "Register write error, aborting.\n");