Message ID | 20230320081702.203843-1-qinyu32@huawei.com |
---|---|
State | Accepted |
Commit | 877d5cd2aeed8fddeb3afe174c6b9eb77cd56f8b |
Headers | show |
Series | [v2] cpufreq: warn about invalid vals to scaling_max/min_freq interfaces | expand |
On Mon, Mar 20, 2023 at 9:09 AM qinyu <qinyu32@huawei.com> wrote: > > When echo an invalid val to scaling_min_freq: > > echo 123abc123 > scaling_min_freq > It looks weird to have a return val of 0: > > echo $? > > 0 > > Sane people won't echo strings like that into these interfaces but fuzz > tests may do. Also, maybe it's better to inform people if input is > invalid. > > After this: > > echo 123abc123 > scaling_min_freq > > -bash: echo: write error: Invalid argument > > Signed-off-by: qinyu <qinyu32@huawei.com> > Tested-by: zhangxiaofeng <zhangxiaofeng46@huawei.com> > Acked-by: Viresh Kumar <viresh.kumar@linaro.org> > --- > v2: > - reword commit message to match the actual code changes. > 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 6d8fd3b8d..d61f7308f 100644 > --- a/drivers/cpufreq/cpufreq.c > +++ b/drivers/cpufreq/cpufreq.c > @@ -725,9 +725,9 @@ static ssize_t store_##file_name \ > unsigned long val; \ > int ret; \ > \ > - ret = sscanf(buf, "%lu", &val); \ > - if (ret != 1) \ > - return -EINVAL; \ > + ret = kstrtoul(buf, 0, &val); \ > + if (ret) \ > + return ret; \ > \ > ret = freq_qos_update_request(policy->object##_freq_req, val);\ > return ret >= 0 ? count : ret; \ > -- Applied as 6.4 material, thanks!
diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index 6d8fd3b8d..d61f7308f 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -725,9 +725,9 @@ static ssize_t store_##file_name \ unsigned long val; \ int ret; \ \ - ret = sscanf(buf, "%lu", &val); \ - if (ret != 1) \ - return -EINVAL; \ + ret = kstrtoul(buf, 0, &val); \ + if (ret) \ + return ret; \ \ ret = freq_qos_update_request(policy->object##_freq_req, val);\ return ret >= 0 ? count : ret; \