cpufreq: Update sscanf() to kstrtouint()
authorBowen Yu <yubowen8@huawei.com>
Mon, 19 May 2025 07:09:38 +0000 (15:09 +0800)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Wed, 21 May 2025 20:27:36 +0000 (22:27 +0200)
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>
Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
Link: https://patch.msgid.link/20250519070938.931396-1-yubowen8@huawei.com
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
drivers/cpufreq/cpufreq.c

index fbd09c0..d7426e1 100644 (file)
@@ -917,9 +917,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);