]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
PM / devfreq: governor: Replace sscanf() with kstrtoul() in set_freq_store()
authorLifeng Zheng <zhenglifeng1@huawei.com>
Mon, 21 Apr 2025 03:00:17 +0000 (11:00 +0800)
committerChanwoo Choi <cw00.choi@samsung.com>
Mon, 14 Jul 2025 11:04:16 +0000 (20:04 +0900)
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>
drivers/devfreq/governor_userspace.c

index d1aa6806b683ac80c40702f9c468ecd3141d6882..175de0c0b50e087861313060eab70a35b757fd20 100644 (file)
@@ -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);