Skip to content

Commit 90e41ba

Browse files
praritDave Jones
authored andcommitted
[CPUFREQ] Fix stale cpufreq_cpu_governor pointer
Dave, Attached is an update of my patch against the cpufreq fixes branch. Before applying the patch I compiled and booted the tree to see if the panic was still there -- to my surprise it was not. This is because of the conversion of cpufreq_cpu_governor to a char[]. While the panic is kaput, the problem of stale data continues and my patch is still valid. It is possible to end up with the wrong governor after hotplug events because CPUFREQ_DEFAULT_GOVERNOR is statically linked to a default, while the cpu siblings may have had a different governor assigned by a user. ie) the patch is still needed in order to keep the governors assigned properly when hotplugging devices Signed-off-by: Prarit Bhargava <prarit@redhat.com> Signed-off-by: Dave Jones <davej@redhat.com>
1 parent 54c9a35 commit 90e41ba

1 file changed

Lines changed: 30 additions & 2 deletions

File tree

‎drivers/cpufreq/cpufreq.c‎

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -951,10 +951,13 @@ int cpufreq_add_dev_interface(unsigned int cpu, struct cpufreq_policy *policy,
951951
static int cpufreq_add_dev(struct sys_device *sys_dev)
952952
{
953953
unsigned int cpu = sys_dev->id;
954-
int ret = 0;
954+
int ret = 0, found = 0;
955955
struct cpufreq_policy *policy;
956956
unsigned long flags;
957957
unsigned int j;
958+
#ifdef CONFIG_HOTPLUG_CPU
959+
int sibling;
960+
#endif
958961

959962
if (cpu_is_offline(cpu))
960963
return 0;
@@ -1001,7 +1004,19 @@ static int cpufreq_add_dev(struct sys_device *sys_dev)
10011004
INIT_WORK(&policy->update, handle_update);
10021005

10031006
/* Set governor before ->init, so that driver could check it */
1004-
policy->governor = CPUFREQ_DEFAULT_GOVERNOR;
1007+
#ifdef CONFIG_HOTPLUG_CPU
1008+
for_each_online_cpu(sibling) {
1009+
struct cpufreq_policy *cp = per_cpu(cpufreq_cpu_data, sibling);
1010+
if (cp && cp->governor &&
1011+
(cpumask_test_cpu(cpu, cp->related_cpus))) {
1012+
policy->governor = cp->governor;
1013+
found = 1;
1014+
break;
1015+
}
1016+
}
1017+
#endif
1018+
if (!found)
1019+
policy->governor = CPUFREQ_DEFAULT_GOVERNOR;
10051020
/* call driver. From then on the cpufreq must be able
10061021
* to accept all calls to ->verify and ->setpolicy for this CPU
10071022
*/
@@ -1610,9 +1625,22 @@ EXPORT_SYMBOL_GPL(cpufreq_register_governor);
16101625

16111626
void cpufreq_unregister_governor(struct cpufreq_governor *governor)
16121627
{
1628+
#ifdef CONFIG_HOTPLUG_CPU
1629+
int cpu;
1630+
#endif
1631+
16131632
if (!governor)
16141633
return;
16151634

1635+
#ifdef CONFIG_HOTPLUG_CPU
1636+
for_each_present_cpu(cpu) {
1637+
if (cpu_online(cpu))
1638+
continue;
1639+
if (!strcmp(per_cpu(cpufreq_cpu_governor, cpu), governor->name))
1640+
strcpy(per_cpu(cpufreq_cpu_governor, cpu), "\0");
1641+
}
1642+
#endif
1643+
16161644
mutex_lock(&cpufreq_governor_mutex);
16171645
list_del(&governor->governor_list);
16181646
mutex_unlock(&cpufreq_governor_mutex);

0 commit comments

Comments
 (0)