Linux Power Management development
 help / color / mirror / Atom feed
From: qinyu <qinyu32@huawei.com>
To: <rafael@kernel.org>, <viresh.kumar@linaro.org>
Cc: <linux-pm@vger.kernel.org>, <zhangxiaofeng46@huawei.com>,
	<hewenliang4@huawei.com>, <linfeilong@huawei.com>
Subject: [PATCH] cpufreq: warn about invalid vals to scaling_max/min_freq interfaces
Date: Thu, 16 Mar 2023 11:15:49 +0800	[thread overview]
Message-ID: <20230316031549.1343340-1-qinyu32@huawei.com> (raw)

When echo an invalid val to scaling_min_freq:
> echo 123abc123 > scaling_min_freq
It looks weird to have a return val of 0:
> echo $?
> 0

Sane people won't echo strings like that into these interfaces but fuzz
tests may do. Also, maybe it's better to inform people if input is invalid
or out of range.

After this:
> echo 123abc123 > scaling_min_freq
> -bash: echo: write error: Invalid argument

Signed-off-by: qinyu <qinyu32@huawei.com>
Tested-by: zhangxiaofeng <zhangxiaofeng46@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 6d8fd3b8d..d61f7308f 100644
--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -725,9 +725,9 @@ static ssize_t store_##file_name					\
 	unsigned long val;						\
 	int ret;							\
 									\
-	ret = sscanf(buf, "%lu", &val);					\
-	if (ret != 1)							\
-		return -EINVAL;						\
+	ret = kstrtoul(buf, 0, &val);					\
+	if (ret)							\
+		return ret;						\
 									\
 	ret = freq_qos_update_request(policy->object##_freq_req, val);\
 	return ret >= 0 ? count : ret;					\
-- 
2.33.0


             reply	other threads:[~2023-03-16  3:11 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-16  3:15 qinyu [this message]
2023-03-16  3:36 ` [PATCH] cpufreq: warn about invalid vals to scaling_max/min_freq interfaces Viresh Kumar
2023-03-17 11:47 ` Russell Haley
2023-03-20  7:36   ` qinyu
2023-03-17 15:41 ` Rafael J. Wysocki
2023-03-20  8:17   ` [PATCH v2] " qinyu
2023-03-22 19:12     ` 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=20230316031549.1343340-1-qinyu32@huawei.com \
    --to=qinyu32@huawei.com \
    --cc=hewenliang4@huawei.com \
    --cc=linfeilong@huawei.com \
    --cc=linux-pm@vger.kernel.org \
    --cc=rafael@kernel.org \
    --cc=viresh.kumar@linaro.org \
    --cc=zhangxiaofeng46@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