Message ID | 20220516030251.42323-1-schspa@gmail.com |
---|---|
State | Superseded |
Headers | show |
Series | [v6,1/2] cpufreq: Abort show/store for half initialized policy | expand |
On Mon, 16 May 2022 at 04:03, Schspa Shi <schspa@gmail.com> wrote: > > If policy initialization fails after the sysfs files are created, > there is a possibility that we may end up running show()/store() > callbacks for half initialized policies, which may have unpredictable > outcomes. > > Abort show/store in such a case by making sure the policy is active. > Also inactivate the policy on such failures. > > Signed-off-by: Schspa Shi <schspa@gmail.com> Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
On Mon, May 16, 2022 at 12:25 PM Viresh Kumar <viresh.kumar@linaro.org> wrote: > > On Mon, 16 May 2022 at 04:03, Schspa Shi <schspa@gmail.com> wrote: > > > > If policy initialization fails after the sysfs files are created, > > there is a possibility that we may end up running show()/store() > > callbacks for half initialized policies, which may have unpredictable > > outcomes. > > > > Abort show/store in such a case by making sure the policy is active. > > Also inactivate the policy on such failures. > > > > Signed-off-by: Schspa Shi <schspa@gmail.com> > > Acked-by: Viresh Kumar <viresh.kumar@linaro.org> Applied along with the [2/2], with some adjustments in the subject and changelog, as 5.19 material. Thanks!
diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index 80f535cc8a75..ba73be6f0490 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -947,13 +947,14 @@ static ssize_t show(struct kobject *kobj, struct attribute *attr, char *buf) { struct cpufreq_policy *policy = to_policy(kobj); struct freq_attr *fattr = to_attr(attr); - ssize_t ret; + ssize_t ret = -EBUSY; if (!fattr->show) return -EIO; down_read(&policy->rwsem); - ret = fattr->show(policy, buf); + if (likely(!policy_is_inactive(policy))) + ret = fattr->show(policy, buf); up_read(&policy->rwsem); return ret; @@ -964,7 +965,7 @@ static ssize_t store(struct kobject *kobj, struct attribute *attr, { struct cpufreq_policy *policy = to_policy(kobj); struct freq_attr *fattr = to_attr(attr); - ssize_t ret = -EINVAL; + ssize_t ret = -EBUSY; if (!fattr->store) return -EIO; @@ -978,7 +979,8 @@ static ssize_t store(struct kobject *kobj, struct attribute *attr, if (cpu_online(policy->cpu)) { down_write(&policy->rwsem); - ret = fattr->store(policy, buf, count); + if (likely(!policy_is_inactive(policy))) + ret = fattr->store(policy, buf, count); up_write(&policy->rwsem); } @@ -1533,6 +1535,7 @@ static int cpufreq_online(unsigned int cpu) for_each_cpu(j, policy->real_cpus) remove_cpu_dev_symlink(policy, get_cpu_device(j)); + cpumask_clear(policy->cpus); up_write(&policy->rwsem); out_offline_policy: