Skip to content

Commit 514ff1b

Browse files
schsparafaeljw
authored andcommitted
cpufreq: make interface functions and lock holding state clear
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>
1 parent d4627a2 commit 514ff1b

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

drivers/cpufreq/cpufreq.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1341,12 +1341,12 @@ static int cpufreq_online(unsigned int cpu)
13411341
down_write(&policy->rwsem);
13421342
policy->cpu = cpu;
13431343
policy->governor = NULL;
1344-
up_write(&policy->rwsem);
13451344
} else {
13461345
new_policy = true;
13471346
policy = cpufreq_policy_alloc(cpu);
13481347
if (!policy)
13491348
return -ENOMEM;
1349+
down_write(&policy->rwsem);
13501350
}
13511351

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

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

15401539
cpumask_clear(policy->cpus);
1541-
up_write(&policy->rwsem);
15421540

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

15511549
out_free_policy:
1550+
up_write(&policy->rwsem);
1551+
15521552
cpufreq_policy_free(policy);
15531553
return ret;
15541554
}

0 commit comments

Comments
 (0)