Skip to content

Commit 914cc79

Browse files
Lifeng Zhengchanwoochoi
authored andcommitted
PM / devfreq: governor: Replace sscanf() with kstrtoul() in set_freq_store()
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>
1 parent 347e9f5 commit 914cc79

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

drivers/devfreq/governor_userspace.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <linux/slab.h>
1010
#include <linux/device.h>
1111
#include <linux/devfreq.h>
12+
#include <linux/kstrtox.h>
1213
#include <linux/pm.h>
1314
#include <linux/mutex.h>
1415
#include <linux/module.h>
@@ -39,10 +40,13 @@ static ssize_t set_freq_store(struct device *dev, struct device_attribute *attr,
3940
unsigned long wanted;
4041
int err = 0;
4142

43+
err = kstrtoul(buf, 0, &wanted);
44+
if (err)
45+
return err;
46+
4247
mutex_lock(&devfreq->lock);
4348
data = devfreq->governor_data;
4449

45-
sscanf(buf, "%lu", &wanted);
4650
data->user_frequency = wanted;
4751
data->valid = true;
4852
err = update_devfreq(devfreq);

0 commit comments

Comments
 (0)