Skip to content

Commit 484d3f1

Browse files
Henry Martinvireshk
authored andcommitted
cpufreq: scmi: Fix null-ptr-deref in scmi_cpufreq_get_rate()
cpufreq_cpu_get_raw() can return NULL when the target CPU is not present in the policy->cpus mask. scmi_cpufreq_get_rate() does not check for this case, which results in a NULL pointer dereference. Add NULL check after cpufreq_cpu_get_raw() to prevent this issue. Fixes: 99d6bdf ("cpufreq: add support for CPU DVFS based on SCMI message protocol") Signed-off-by: Henry Martin <bsdhenrymartin@gmail.com> Acked-by: Sudeep Holla <sudeep.holla@arm.com> Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
1 parent 9992649 commit 484d3f1

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

drivers/cpufreq/scmi-cpufreq.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,17 @@ static struct cpufreq_driver scmi_cpufreq_driver;
3737

3838
static unsigned int scmi_cpufreq_get_rate(unsigned int cpu)
3939
{
40-
struct cpufreq_policy *policy = cpufreq_cpu_get_raw(cpu);
41-
struct scmi_data *priv = policy->driver_data;
40+
struct cpufreq_policy *policy;
41+
struct scmi_data *priv;
4242
unsigned long rate;
4343
int ret;
4444

45+
policy = cpufreq_cpu_get_raw(cpu);
46+
if (unlikely(!policy))
47+
return 0;
48+
49+
priv = policy->driver_data;
50+
4551
ret = perf_ops->freq_get(ph, priv->domain_id, &rate, false);
4652
if (ret)
4753
return 0;

0 commit comments

Comments
 (0)