From: "yubowen (H)" <yubowen8@huawei.com>
To: David Laight <david.laight.linux@gmail.com>
Cc: "rafael@kernel.org" <rafael@kernel.org>,
"viresh.kumar@linaro.org" <viresh.kumar@linaro.org>,
"linux-pm@vger.kernel.org" <linux-pm@vger.kernel.org>,
"linux-kernel@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>
Subject: 回复: [PATCH] cpufreq: Update sscanf() to kstrtouint()
Date: Wed, 21 May 2025 01:05:18 +0000 [thread overview]
Message-ID: <943bdb6ace1f4b92b9f26e78d7efbe30@huawei.com> (raw)
In-Reply-To: <20250519224648.41f2460d@pumpkin>
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);
>
next prev parent reply other threads:[~2025-05-21 1:05 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
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) [this message]
2025-05-21 20:33 ` Rafael J. Wysocki
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=943bdb6ace1f4b92b9f26e78d7efbe30@huawei.com \
--to=yubowen8@huawei.com \
--cc=cenxinghai@h-partners.com \
--cc=david.laight.linux@gmail.com \
--cc=jonathan.cameron@huawei.com \
--cc=lihuisong@huawei.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=linuxarm@huawei.com \
--cc=rafael@kernel.org \
--cc=viresh.kumar@linaro.org \
--cc=zhanjie9@hisilicon.com \
--cc=zhenglifeng1@huawei.com \
/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