Skip to content

Commit d4627a2

Browse files
schsparafaeljw
authored andcommitted
cpufreq: Abort show()/store() for half-initialized policies
If policy initialization fails after the sysfs files are created, there is a possibility to 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 dectivate the policy on such failures. Signed-off-by: Schspa Shi <schspa@gmail.com> Acked-by: Viresh Kumar <viresh.kumar@linaro.org> [ rjw: Subject and changelog edits ] Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent f339f35 commit d4627a2

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

drivers/cpufreq/cpufreq.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -948,13 +948,14 @@ static ssize_t show(struct kobject *kobj, struct attribute *attr, char *buf)
948948
{
949949
struct cpufreq_policy *policy = to_policy(kobj);
950950
struct freq_attr *fattr = to_attr(attr);
951-
ssize_t ret;
951+
ssize_t ret = -EBUSY;
952952

953953
if (!fattr->show)
954954
return -EIO;
955955

956956
down_read(&policy->rwsem);
957-
ret = fattr->show(policy, buf);
957+
if (likely(!policy_is_inactive(policy)))
958+
ret = fattr->show(policy, buf);
958959
up_read(&policy->rwsem);
959960

960961
return ret;
@@ -965,7 +966,7 @@ static ssize_t store(struct kobject *kobj, struct attribute *attr,
965966
{
966967
struct cpufreq_policy *policy = to_policy(kobj);
967968
struct freq_attr *fattr = to_attr(attr);
968-
ssize_t ret = -EINVAL;
969+
ssize_t ret = -EBUSY;
969970

970971
if (!fattr->store)
971972
return -EIO;
@@ -979,7 +980,8 @@ static ssize_t store(struct kobject *kobj, struct attribute *attr,
979980

980981
if (cpu_online(policy->cpu)) {
981982
down_write(&policy->rwsem);
982-
ret = fattr->store(policy, buf, count);
983+
if (likely(!policy_is_inactive(policy)))
984+
ret = fattr->store(policy, buf, count);
983985
up_write(&policy->rwsem);
984986
}
985987

@@ -1535,6 +1537,7 @@ static int cpufreq_online(unsigned int cpu)
15351537
for_each_cpu(j, policy->real_cpus)
15361538
remove_cpu_dev_symlink(policy, j, get_cpu_device(j));
15371539

1540+
cpumask_clear(policy->cpus);
15381541
up_write(&policy->rwsem);
15391542

15401543
out_offline_policy:

0 commit comments

Comments
 (0)