Skip to content

Commit f1728fd

Browse files
committed
Merge branch 'pm-cpufreq'
* pm-cpufreq: cpufreq: Acquire the lock in cpufreq_policy_restore() for reading cpufreq: Prevent problems in update_policy_cpu() if last_cpu == new_cpu cpufreq: Restructure if/else block to avoid unintended behavior cpufreq: Fix crash in cpufreq-stats during suspend/resume
2 parents 0df03a3 + 44871c9 commit f1728fd

1 file changed

Lines changed: 32 additions & 17 deletions

File tree

‎drivers/cpufreq/cpufreq.c‎

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -906,11 +906,11 @@ static struct cpufreq_policy *cpufreq_policy_restore(unsigned int cpu)
906906
struct cpufreq_policy *policy;
907907
unsigned long flags;
908908

909-
write_lock_irqsave(&cpufreq_driver_lock, flags);
909+
read_lock_irqsave(&cpufreq_driver_lock, flags);
910910

911911
policy = per_cpu(cpufreq_cpu_data_fallback, cpu);
912912

913-
write_unlock_irqrestore(&cpufreq_driver_lock, flags);
913+
read_unlock_irqrestore(&cpufreq_driver_lock, flags);
914914

915915
return policy;
916916
}
@@ -947,6 +947,21 @@ static void cpufreq_policy_free(struct cpufreq_policy *policy)
947947
kfree(policy);
948948
}
949949

950+
static void update_policy_cpu(struct cpufreq_policy *policy, unsigned int cpu)
951+
{
952+
if (cpu == policy->cpu)
953+
return;
954+
955+
policy->last_cpu = policy->cpu;
956+
policy->cpu = cpu;
957+
958+
#ifdef CONFIG_CPU_FREQ_TABLE
959+
cpufreq_frequency_table_update_policy_cpu(policy);
960+
#endif
961+
blocking_notifier_call_chain(&cpufreq_policy_notifier_list,
962+
CPUFREQ_UPDATE_POLICY_CPU, policy);
963+
}
964+
950965
static int __cpufreq_add_dev(struct device *dev, struct subsys_interface *sif,
951966
bool frozen)
952967
{
@@ -1000,7 +1015,18 @@ static int __cpufreq_add_dev(struct device *dev, struct subsys_interface *sif,
10001015
if (!policy)
10011016
goto nomem_out;
10021017

1003-
policy->cpu = cpu;
1018+
1019+
/*
1020+
* In the resume path, since we restore a saved policy, the assignment
1021+
* to policy->cpu is like an update of the existing policy, rather than
1022+
* the creation of a brand new one. So we need to perform this update
1023+
* by invoking update_policy_cpu().
1024+
*/
1025+
if (frozen && cpu != policy->cpu)
1026+
update_policy_cpu(policy, cpu);
1027+
else
1028+
policy->cpu = cpu;
1029+
10041030
policy->governor = CPUFREQ_DEFAULT_GOVERNOR;
10051031
cpumask_copy(policy->cpus, cpumask_of(cpu));
10061032

@@ -1092,18 +1118,6 @@ static int cpufreq_add_dev(struct device *dev, struct subsys_interface *sif)
10921118
return __cpufreq_add_dev(dev, sif, false);
10931119
}
10941120

1095-
static void update_policy_cpu(struct cpufreq_policy *policy, unsigned int cpu)
1096-
{
1097-
policy->last_cpu = policy->cpu;
1098-
policy->cpu = cpu;
1099-
1100-
#ifdef CONFIG_CPU_FREQ_TABLE
1101-
cpufreq_frequency_table_update_policy_cpu(policy);
1102-
#endif
1103-
blocking_notifier_call_chain(&cpufreq_policy_notifier_list,
1104-
CPUFREQ_UPDATE_POLICY_CPU, policy);
1105-
}
1106-
11071121
static int cpufreq_nominate_new_policy_cpu(struct cpufreq_policy *policy,
11081122
unsigned int old_cpu, bool frozen)
11091123
{
@@ -1182,8 +1196,9 @@ static int __cpufreq_remove_dev_prepare(struct device *dev,
11821196
cpumask_clear_cpu(cpu, policy->cpus);
11831197
unlock_policy_rwsem_write(cpu);
11841198

1185-
if (cpu != policy->cpu && !frozen) {
1186-
sysfs_remove_link(&dev->kobj, "cpufreq");
1199+
if (cpu != policy->cpu) {
1200+
if (!frozen)
1201+
sysfs_remove_link(&dev->kobj, "cpufreq");
11871202
} else if (cpus > 1) {
11881203

11891204
new_cpu = cpufreq_nominate_new_policy_cpu(policy, cpu, frozen);

0 commit comments

Comments
 (0)