* [PATCH] cpufreq: Update sscanf() to kstrtouint()
@ 2025-05-19 7:09 Bowen Yu
2025-05-19 10:04 ` Viresh Kumar
2025-05-19 21:46 ` David Laight
0 siblings, 2 replies; 6+ messages in thread
From: Bowen Yu @ 2025-05-19 7:09 UTC (permalink / raw)
To: rafael, viresh.kumar
Cc: linux-pm, linux-kernel, linuxarm, zhanjie9, jonathan.cameron,
lihuisong, zhenglifeng1, yubowen8, cenxinghai
In store_scaling_setspeed(), sscanf is still used to read to sysfs.
Newer kstrtox provide more features including overflow protection,
better errorhandling and allows for other systems of numeration. It
is therefore better to update sscanf() to kstrtouint().
Signed-off-by: Bowen Yu <yubowen8@huawei.com>
---
drivers/cpufreq/cpufreq.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
index be727da0be4d..0c842edd1a76 100644
--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -920,9 +920,9 @@ static ssize_t store_scaling_setspeed(struct cpufreq_policy *policy,
if (!policy->governor || !policy->governor->store_setspeed)
return -EINVAL;
- ret = sscanf(buf, "%u", &freq);
- if (ret != 1)
- return -EINVAL;
+ ret = kstrtouint(buf, 0, &freq);
+ if (ret)
+ return ret;
policy->governor->store_setspeed(policy, freq);
--
2.33.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] cpufreq: Update sscanf() to kstrtouint()
2025-05-19 7:09 [PATCH] cpufreq: Update sscanf() to kstrtouint() Bowen Yu
@ 2025-05-19 10:04 ` Viresh Kumar
2025-05-21 20:28 ` Rafael J. Wysocki
2025-05-19 21:46 ` David Laight
1 sibling, 1 reply; 6+ messages in thread
From: Viresh Kumar @ 2025-05-19 10:04 UTC (permalink / raw)
To: Bowen Yu
Cc: rafael, linux-pm, linux-kernel, linuxarm, zhanjie9,
jonathan.cameron, lihuisong, zhenglifeng1, cenxinghai
On 19-05-25, 15:09, Bowen Yu wrote:
> In store_scaling_setspeed(), sscanf is still used to read to sysfs.
> Newer kstrtox provide more features including overflow protection,
> better errorhandling and allows for other systems of numeration. It
> is therefore better to update sscanf() to kstrtouint().
>
> Signed-off-by: Bowen Yu <yubowen8@huawei.com>
> ---
> drivers/cpufreq/cpufreq.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
> index be727da0be4d..0c842edd1a76 100644
> --- a/drivers/cpufreq/cpufreq.c
> +++ b/drivers/cpufreq/cpufreq.c
> @@ -920,9 +920,9 @@ static ssize_t store_scaling_setspeed(struct cpufreq_policy *policy,
> if (!policy->governor || !policy->governor->store_setspeed)
> return -EINVAL;
>
> - ret = sscanf(buf, "%u", &freq);
> - if (ret != 1)
> - return -EINVAL;
> + ret = kstrtouint(buf, 0, &freq);
> + if (ret)
> + return ret;
>
> policy->governor->store_setspeed(policy, freq);
Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
--
viresh
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] cpufreq: Update sscanf() to kstrtouint()
2025-05-19 7:09 [PATCH] cpufreq: Update sscanf() to kstrtouint() Bowen Yu
2025-05-19 10:04 ` Viresh Kumar
@ 2025-05-19 21:46 ` David Laight
2025-05-21 1:05 ` 回复: " yubowen (H)
2025-05-21 20:33 ` Rafael J. Wysocki
1 sibling, 2 replies; 6+ messages in thread
From: David Laight @ 2025-05-19 21:46 UTC (permalink / raw)
To: Bowen Yu
Cc: rafael, viresh.kumar, linux-pm, linux-kernel, linuxarm, zhanjie9,
jonathan.cameron, lihuisong, zhenglifeng1, cenxinghai
On Mon, 19 May 2025 15:09:38 +0800
Bowen Yu <yubowen8@huawei.com> wrote:
> In store_scaling_setspeed(), sscanf is still used to read to sysfs.
> Newer kstrtox provide more features including overflow protection,
> better errorhandling and allows for other systems of numeration. It
> is therefore better to update sscanf() to kstrtouint().
This is a UAPI change.
Since the value is a frequency there could easily be scripts
that append Hz to the value.
You're making them fail.
David
>
> Signed-off-by: Bowen Yu <yubowen8@huawei.com>
> ---
> drivers/cpufreq/cpufreq.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
> index be727da0be4d..0c842edd1a76 100644
> --- a/drivers/cpufreq/cpufreq.c
> +++ b/drivers/cpufreq/cpufreq.c
> @@ -920,9 +920,9 @@ static ssize_t store_scaling_setspeed(struct cpufreq_policy *policy,
> if (!policy->governor || !policy->governor->store_setspeed)
> return -EINVAL;
>
> - ret = sscanf(buf, "%u", &freq);
> - if (ret != 1)
> - return -EINVAL;
> + ret = kstrtouint(buf, 0, &freq);
> + if (ret)
> + return ret;
>
> policy->governor->store_setspeed(policy, freq);
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* 回复: [PATCH] cpufreq: Update sscanf() to kstrtouint()
2025-05-19 21:46 ` David Laight
@ 2025-05-21 1:05 ` yubowen (H)
2025-05-21 20:33 ` Rafael J. Wysocki
1 sibling, 0 replies; 6+ messages in thread
From: yubowen (H) @ 2025-05-21 1:05 UTC (permalink / raw)
To: David Laight
Cc: rafael@kernel.org, viresh.kumar@linaro.org,
linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Linuxarm,
Zhanjie, Jonathan Cameron, lihuisong (C), zhenglifeng (A),
cenxinghai
Hi David,
Thanks for reviewing.
I think since reading the frequency value gives only value and not unit, the input should stay coherent and only take numbers as valid input instead of accepting all user input with numbers at the beginning. In addition, previous patches have changed other places that used sscanf() in this file and it is better to stay consistent.
Would you say that this makes sense?
Best regards,
Bowen Yu
-----邮件原件-----
发件人: David Laight <david.laight.linux@gmail.com>
发送时间: 2025年5月20日 5:47
收件人: yubowen (H) <yubowen8@huawei.com>
抄送: rafael@kernel.org; viresh.kumar@linaro.org; linux-pm@vger.kernel.org; linux-kernel@vger.kernel.org; Linuxarm <linuxarm@huawei.com>; Zhanjie <zhanjie9@hisilicon.com>; Jonathan Cameron <jonathan.cameron@huawei.com>; lihuisong (C) <lihuisong@huawei.com>; zhenglifeng (A) <zhenglifeng1@huawei.com>; cenxinghai <cenxinghai@h-partners.com>
主题: Re: [PATCH] cpufreq: Update sscanf() to kstrtouint()
On Mon, 19 May 2025 15:09:38 +0800
Bowen Yu <yubowen8@huawei.com> wrote:
> In store_scaling_setspeed(), sscanf is still used to read to sysfs.
> Newer kstrtox provide more features including overflow protection,
> better errorhandling and allows for other systems of numeration. It is
> therefore better to update sscanf() to kstrtouint().
This is a UAPI change.
Since the value is a frequency there could easily be scripts that append Hz to the value.
You're making them fail.
David
>
> Signed-off-by: Bowen Yu <yubowen8@huawei.com>
> ---
> drivers/cpufreq/cpufreq.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
> index be727da0be4d..0c842edd1a76 100644
> --- a/drivers/cpufreq/cpufreq.c
> +++ b/drivers/cpufreq/cpufreq.c
> @@ -920,9 +920,9 @@ static ssize_t store_scaling_setspeed(struct cpufreq_policy *policy,
> if (!policy->governor || !policy->governor->store_setspeed)
> return -EINVAL;
>
> - ret = sscanf(buf, "%u", &freq);
> - if (ret != 1)
> - return -EINVAL;
> + ret = kstrtouint(buf, 0, &freq);
> + if (ret)
> + return ret;
>
> policy->governor->store_setspeed(policy, freq);
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] cpufreq: Update sscanf() to kstrtouint()
2025-05-19 10:04 ` Viresh Kumar
@ 2025-05-21 20:28 ` Rafael J. Wysocki
0 siblings, 0 replies; 6+ messages in thread
From: Rafael J. Wysocki @ 2025-05-21 20:28 UTC (permalink / raw)
To: Viresh Kumar, Bowen Yu
Cc: linux-pm, linux-kernel, linuxarm, zhanjie9, jonathan.cameron,
lihuisong, zhenglifeng1, cenxinghai
On Mon, May 19, 2025 at 12:04 PM Viresh Kumar <viresh.kumar@linaro.org> wrote:
>
> On 19-05-25, 15:09, Bowen Yu wrote:
> > In store_scaling_setspeed(), sscanf is still used to read to sysfs.
> > Newer kstrtox provide more features including overflow protection,
> > better errorhandling and allows for other systems of numeration. It
> > is therefore better to update sscanf() to kstrtouint().
> >
> > Signed-off-by: Bowen Yu <yubowen8@huawei.com>
> > ---
> > drivers/cpufreq/cpufreq.c | 6 +++---
> > 1 file changed, 3 insertions(+), 3 deletions(-)
> >
> > diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
> > index be727da0be4d..0c842edd1a76 100644
> > --- a/drivers/cpufreq/cpufreq.c
> > +++ b/drivers/cpufreq/cpufreq.c
> > @@ -920,9 +920,9 @@ static ssize_t store_scaling_setspeed(struct cpufreq_policy *policy,
> > if (!policy->governor || !policy->governor->store_setspeed)
> > return -EINVAL;
> >
> > - ret = sscanf(buf, "%u", &freq);
> > - if (ret != 1)
> > - return -EINVAL;
> > + ret = kstrtouint(buf, 0, &freq);
> > + if (ret)
> > + return ret;
> >
> > policy->governor->store_setspeed(policy, freq);
>
> Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
Applied as 6.16 material, thanks!
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] cpufreq: Update sscanf() to kstrtouint()
2025-05-19 21:46 ` David Laight
2025-05-21 1:05 ` 回复: " yubowen (H)
@ 2025-05-21 20:33 ` Rafael J. Wysocki
1 sibling, 0 replies; 6+ messages in thread
From: Rafael J. Wysocki @ 2025-05-21 20:33 UTC (permalink / raw)
To: David Laight
Cc: Bowen Yu, rafael, viresh.kumar, linux-pm, linux-kernel, linuxarm,
zhanjie9, jonathan.cameron, lihuisong, zhenglifeng1, cenxinghai
On Mon, May 19, 2025 at 11:46 PM David Laight
<david.laight.linux@gmail.com> wrote:
>
> On Mon, 19 May 2025 15:09:38 +0800
> Bowen Yu <yubowen8@huawei.com> wrote:
>
> > In store_scaling_setspeed(), sscanf is still used to read to sysfs.
> > Newer kstrtox provide more features including overflow protection,
> > better errorhandling and allows for other systems of numeration. It
> > is therefore better to update sscanf() to kstrtouint().
>
> This is a UAPI change.
> Since the value is a frequency there could easily be scripts
> that append Hz to the value.
Which would be incorrect because the value is in kHz.
They are not expected to do so in any case, though, so hopefully there
are none, in which case we don't want any to appear in the future.
> You're making them fail.
So if there are any, we'll get to know.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2025-05-21 20:33 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-19 7:09 [PATCH] cpufreq: Update sscanf() to kstrtouint() Bowen Yu
2025-05-19 10:04 ` Viresh Kumar
2025-05-21 20:28 ` Rafael J. Wysocki
2025-05-19 21:46 ` David Laight
2025-05-21 1:05 ` 回复: " yubowen (H)
2025-05-21 20:33 ` Rafael J. Wysocki
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox