summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLifeng Zheng <zhenglifeng1@huawei.com>2025-04-21 11:00:17 +0800
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2025-08-20 18:35:55 +0200
commitbdde0079d0bf2ac1282ccc53984b01346fb28419 (patch)
treea7d62f152b3c2637188b4d3b189c69d41c1d5215
parent47769dab9073a73e127aa0bfd0ba4c51eaccdc33 (diff)
PM / devfreq: governor: Replace sscanf() with kstrtoul() in set_freq_store()
[ Upstream commit 914cc799b28f17d369d5b4db3b941957d18157e8 ] Replace sscanf() with kstrtoul() in set_freq_store() and check the result to avoid invalid input. Signed-off-by: Lifeng Zheng <zhenglifeng1@huawei.com> Link: https://lore.kernel.org/lkml/20250421030020.3108405-2-zhenglifeng1@huawei.com/ Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
-rw-r--r--drivers/devfreq/governor_userspace.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/drivers/devfreq/governor_userspace.c b/drivers/devfreq/governor_userspace.c
index d1aa6806b683..175de0c0b50e 100644
--- a/drivers/devfreq/governor_userspace.c
+++ b/drivers/devfreq/governor_userspace.c
@@ -9,6 +9,7 @@
#include <linux/slab.h>
#include <linux/device.h>
#include <linux/devfreq.h>
+#include <linux/kstrtox.h>
#include <linux/pm.h>
#include <linux/mutex.h>
#include <linux/module.h>
@@ -39,10 +40,13 @@ static ssize_t set_freq_store(struct device *dev, struct device_attribute *attr,
unsigned long wanted;
int err = 0;
+ err = kstrtoul(buf, 0, &wanted);
+ if (err)
+ return err;
+
mutex_lock(&devfreq->lock);
data = devfreq->governor_data;
- sscanf(buf, "%lu", &wanted);
data->user_frequency = wanted;
data->valid = true;
err = update_devfreq(devfreq);