Skip to content

Commit

Permalink
cpufreq: make interface functions and lock holding state clear
Browse files Browse the repository at this point in the history
cpufreq_offline() calls offline() and exit() under the policy rwsem
But they are called outside the rwsem in cpufreq_online().

Make cpufreq_online() call offline() and exit() as well as online() and
init() under the policy rwsem to achieve a clear lock relationship.

All of the init() and online() implementations in the tree only
initialize the policy object without attempting to acquire the policy
rwsem and they won't call cpufreq APIs attempting to acquire it.

Signed-off-by: Schspa Shi <schspa@gmail.com>
Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
[ rjw: Changelog edits ]
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
  • Loading branch information
Schspa Shi authored and Rafael J. Wysocki committed May 17, 2022
1 parent d4627a2 commit 514ff1b
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions drivers/cpufreq/cpufreq.c
Original file line number Diff line number Diff line change
Expand Up @@ -1341,12 +1341,12 @@ static int cpufreq_online(unsigned int cpu)
down_write(&policy->rwsem);
policy->cpu = cpu;
policy->governor = NULL;
up_write(&policy->rwsem);
} else {
new_policy = true;
policy = cpufreq_policy_alloc(cpu);
if (!policy)
return -ENOMEM;
down_write(&policy->rwsem);
}

if (!new_policy && cpufreq_driver->online) {
Expand Down Expand Up @@ -1386,7 +1386,6 @@ static int cpufreq_online(unsigned int cpu)
cpumask_copy(policy->related_cpus, policy->cpus);
}

down_write(&policy->rwsem);
/*
* affected cpus must always be the one, which are online. We aren't
* managing offline cpus here.
Expand Down Expand Up @@ -1538,7 +1537,6 @@ static int cpufreq_online(unsigned int cpu)
remove_cpu_dev_symlink(policy, j, get_cpu_device(j));

cpumask_clear(policy->cpus);
up_write(&policy->rwsem);

out_offline_policy:
if (cpufreq_driver->offline)
Expand All @@ -1549,6 +1547,8 @@ static int cpufreq_online(unsigned int cpu)
cpufreq_driver->exit(policy);

out_free_policy:
up_write(&policy->rwsem);

cpufreq_policy_free(policy);
return ret;
}
Expand Down

0 comments on commit 514ff1b

Please sign in to comment.