Skip to content

Commit 387b517

Browse files
committed
cpufreq: Consolidate some code in cpufreq_online()
Notice that the policy->cpu update in cpufreq_policy_alloc() can be moved to cpufreq_online() and then it can be carried out under the policy rwsem, along with the clearing of policy->governor (unnecessary in the "new policy" code branch, but also not harmful). If this is done, the bottom parts of the "if (policy)" branches become identical and they can be collapsed and moved below the conditional. Modify the code accordingly which makes it somewhat easier to follow. No intentional functional impact. Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> Acked-by: Viresh Kumar <viresh.kumar@linaro.org> Reviewed-by: Mario Limonciello <mario.limonciello@amd.com> Acked-by: Sudeep Holla <sudeep.holla@arm.com> Tested-by: Sudeep Holla <sudeep.holla@arm.com> Link: https://patch.msgid.link/13741234.uLZWGnKmhe@rjwysocki.net
1 parent 0af2f6b commit 387b517

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

drivers/cpufreq/cpufreq.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1334,7 +1334,6 @@ static struct cpufreq_policy *cpufreq_policy_alloc(unsigned int cpu)
13341334
init_waitqueue_head(&policy->transition_wait);
13351335
INIT_WORK(&policy->update, handle_update);
13361336

1337-
policy->cpu = cpu;
13381337
return policy;
13391338

13401339
err_min_qos_notifier:
@@ -1422,17 +1421,18 @@ static int cpufreq_online(unsigned int cpu)
14221421

14231422
/* This is the only online CPU for the policy. Start over. */
14241423
new_policy = false;
1425-
down_write(&policy->rwsem);
1426-
policy->cpu = cpu;
1427-
policy->governor = NULL;
14281424
} else {
14291425
new_policy = true;
14301426
policy = cpufreq_policy_alloc(cpu);
14311427
if (!policy)
14321428
return -ENOMEM;
1433-
down_write(&policy->rwsem);
14341429
}
14351430

1431+
down_write(&policy->rwsem);
1432+
1433+
policy->cpu = cpu;
1434+
policy->governor = NULL;
1435+
14361436
if (!new_policy && cpufreq_driver->online) {
14371437
/* Recover policy->cpus using related_cpus */
14381438
cpumask_copy(policy->cpus, policy->related_cpus);

0 commit comments

Comments
 (0)