Skip to content
This repository was archived by the owner on Dec 20, 2023. It is now read-only.

Commit 5a7e56a

Browse files
vireshkrafaeljw
authored andcommitted
cpufreq: Initialize policy before making it available for others to use
Policy must be fully initialized before it is being made available for use by others. Otherwise cpufreq_cpu_get() would be able to grab a half initialized policy structure that might not have affected_cpus (for example) populated. Then, anybody accessing those fields will get a wrong value and that will lead to unpredictable results. In order to fix this, do all the necessary initialization before we make the policy structure available via cpufreq_cpu_get(). That will guarantee that any code accessing fields of the policy will get correct data from them. Reported-by: Saravana Kannan <[email protected]> Signed-off-by: Viresh Kumar <[email protected]> [rjw: Changelog] Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent 999976e commit 5a7e56a

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

drivers/cpufreq/cpufreq.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1109,6 +1109,20 @@ static int __cpufreq_add_dev(struct device *dev, struct subsys_interface *sif,
11091109
goto err_set_policy_cpu;
11101110
}
11111111

1112+
/* related cpus should atleast have policy->cpus */
1113+
cpumask_or(policy->related_cpus, policy->related_cpus, policy->cpus);
1114+
1115+
/*
1116+
* affected cpus must always be the one, which are online. We aren't
1117+
* managing offline cpus here.
1118+
*/
1119+
cpumask_and(policy->cpus, policy->cpus, cpu_online_mask);
1120+
1121+
if (!frozen) {
1122+
policy->user_policy.min = policy->min;
1123+
policy->user_policy.max = policy->max;
1124+
}
1125+
11121126
write_lock_irqsave(&cpufreq_driver_lock, flags);
11131127
for_each_cpu(j, policy->cpus)
11141128
per_cpu(cpufreq_cpu_data, j) = policy;
@@ -1162,20 +1176,6 @@ static int __cpufreq_add_dev(struct device *dev, struct subsys_interface *sif,
11621176
}
11631177
}
11641178

1165-
/* related cpus should atleast have policy->cpus */
1166-
cpumask_or(policy->related_cpus, policy->related_cpus, policy->cpus);
1167-
1168-
/*
1169-
* affected cpus must always be the one, which are online. We aren't
1170-
* managing offline cpus here.
1171-
*/
1172-
cpumask_and(policy->cpus, policy->cpus, cpu_online_mask);
1173-
1174-
if (!frozen) {
1175-
policy->user_policy.min = policy->min;
1176-
policy->user_policy.max = policy->max;
1177-
}
1178-
11791179
blocking_notifier_call_chain(&cpufreq_policy_notifier_list,
11801180
CPUFREQ_START, policy);
11811181

0 commit comments

Comments
 (0)