From: Quentin Schulz <quentin.schulz@cherry.de>
To: Guenter Roeck <linux@roeck-us.net>, linux-hwmon@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, Farouk Bouabid <farouk.bouabid@cherry.de>
Subject: Re: [PATCH v2 01/11] hwmon: (amc6821) Stop accepting invalid pwm values
Date: Wed, 3 Jul 2024 16:29:13 +0200 [thread overview]
Message-ID: <42ab8d15-a195-42d4-a191-a25da00f4c8d@cherry.de> (raw)
In-Reply-To: <20240701212348.1670617-2-linux@roeck-us.net>
Hi Guenter,
On 7/1/24 11:23 PM, Guenter Roeck wrote:
> The pwm value range is well defined from 0..255. Don't accept
> any values outside this range.
>
> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
> ---
> v2: Use kstrtou8() instead of kstrtol() where possible.
> Limit range of pwm1_auto_point_pwm to 0..254 in patch 1
> instead of limiting it later, and do not accept invalid
> values for the attribute.
>
> drivers/hwmon/amc6821.c | 15 +++++++++------
> 1 file changed, 9 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/hwmon/amc6821.c b/drivers/hwmon/amc6821.c
> index 9b02b304c2f5..eb2d5592a41a 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,16 @@ 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 = kstrtou8(buf, 10, &val);
> if (ret)
> return ret;
>
> + if (val > 254)
Would have appreciated a comment as to why it's 254. My understanding is
that the subsystem requires no overlap between multiple pwm_auto_points?
0 being 0 and 2 being 255, we need 1 to be 255?
Actually, that doesn't explain why we allow 0 here, so maybe I'm just
clueless :)
The change itself though:
Reviewed-by: Quentin Schulz <quentin.schulz@cherry.de>
Thanks!
Quentin
next prev parent reply other threads:[~2024-07-03 14:29 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-01 21:23 [PATCH v2 00/11] hwmon: (amc6821) Various improvements Guenter Roeck
2024-07-01 21:23 ` [PATCH v2 01/11] hwmon: (amc6821) Stop accepting invalid pwm values Guenter Roeck
2024-07-03 14:29 ` Quentin Schulz [this message]
2024-07-03 20:17 ` Guenter Roeck
2024-07-01 21:23 ` [PATCH v2 02/11] hwmon: (amc6821) Make reading and writing fan speed limits consistent Guenter Roeck
2024-07-03 14:35 ` Quentin Schulz
2024-07-03 21:48 ` Guenter Roeck
2024-07-04 7:52 ` Quentin Schulz
2024-07-04 17:50 ` Guenter Roeck
2024-07-01 21:23 ` [PATCH v2 03/11] hwmon: (amc6821) Rename fan1_div to fan1_pulses Guenter Roeck
2024-07-01 21:23 ` [PATCH v2 04/11] hwmon: (amc6821) Add support for fan1_target and pwm1_enable mode 4 Guenter Roeck
2024-07-03 14:43 ` Quentin Schulz
2024-07-01 21:23 ` [PATCH v2 05/11] hwmon: (amc2821) Reorder include files, drop unnecessary ones Guenter Roeck
2024-07-01 21:23 ` [PATCH v2 06/11] hwmon: (amc6821) Use tabs for column alignment in defines Guenter Roeck
2024-07-01 21:23 ` [PATCH v2 07/11] hwmon: (amc2821) Use BIT() and GENMASK() Guenter Roeck
2024-07-03 14:45 ` Quentin Schulz
2024-07-01 21:23 ` [PATCH v2 08/11] hwmon: (amc6821) Drop unnecessary enum chips Guenter Roeck
2024-07-01 21:23 ` [PATCH v2 09/11] hwmon: (amc6821) Convert to use regmap Guenter Roeck
2024-07-03 16:19 ` Quentin Schulz
2024-07-03 20:55 ` Guenter Roeck
2024-07-01 21:23 ` [PATCH v2 10/11] hwmon: (amc6821) Convert to with_info API Guenter Roeck
2024-07-03 15:34 ` Quentin Schulz
2024-07-01 21:23 ` [PATCH v2 11/11] hwmon: (amc6821) Add support for pwm1_mode attribute Guenter Roeck
2024-07-03 15:28 ` Quentin Schulz
2024-07-03 21:29 ` Guenter Roeck
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=42ab8d15-a195-42d4-a191-a25da00f4c8d@cherry.de \
--to=quentin.schulz@cherry.de \
--cc=farouk.bouabid@cherry.de \
--cc=linux-hwmon@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@roeck-us.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox