public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [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

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