Skip to content

Commit 9992649

Browse files
Henry Martinvireshk
authored andcommitted
cpufreq: apple-soc: Fix null-ptr-deref in apple_soc_cpufreq_get_rate()
cpufreq_cpu_get_raw() can return NULL when the target CPU is not present in the policy->cpus mask. apple_soc_cpufreq_get_rate() does not check for this case, which results in a NULL pointer dereference. Fixes: 6286bbb ("cpufreq: apple-soc: Add new driver to control Apple SoC CPU P-states") Signed-off-by: Henry Martin <bsdhenrymartin@gmail.com> Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
1 parent d4f610a commit 9992649

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

drivers/cpufreq/apple-soc-cpufreq.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,17 @@ static const struct of_device_id apple_soc_cpufreq_of_match[] __maybe_unused = {
134134

135135
static unsigned int apple_soc_cpufreq_get_rate(unsigned int cpu)
136136
{
137-
struct cpufreq_policy *policy = cpufreq_cpu_get_raw(cpu);
138-
struct apple_cpu_priv *priv = policy->driver_data;
137+
struct cpufreq_policy *policy;
138+
struct apple_cpu_priv *priv;
139139
struct cpufreq_frequency_table *p;
140140
unsigned int pstate;
141141

142+
policy = cpufreq_cpu_get_raw(cpu);
143+
if (unlikely(!policy))
144+
return 0;
145+
146+
priv = policy->driver_data;
147+
142148
if (priv->info->cur_pstate_mask) {
143149
u32 reg = readl_relaxed(priv->reg_base + APPLE_DVFS_STATUS);
144150

0 commit comments

Comments
 (0)