]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
cpufreq: scpi: Fix null-ptr-deref in scpi_cpufreq_get_rate()
authorHenry Martin <bsdhenrymartin@gmail.com>
Tue, 8 Apr 2025 15:03:54 +0000 (23:03 +0800)
committerViresh Kumar <viresh.kumar@linaro.org>
Thu, 10 Apr 2025 04:39:03 +0000 (10:09 +0530)
cpufreq_cpu_get_raw() can return NULL when the target CPU is not present
in the policy->cpus mask. scpi_cpufreq_get_rate() does not check for
this case, which results in a NULL pointer dereference.

Fixes: 343a8d17fa8d ("cpufreq: scpi: remove arm_big_little dependency")
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>
drivers/cpufreq/scpi-cpufreq.c

index 17cda84f00dfb9458889ca750e932944c0bdfe37..dcbb0ae7dd476cc3cdd9893388bbefcaa0f98ca1 100644 (file)
@@ -29,9 +29,16 @@ static struct scpi_ops *scpi_ops;
 
 static unsigned int scpi_cpufreq_get_rate(unsigned int cpu)
 {
-       struct cpufreq_policy *policy = cpufreq_cpu_get_raw(cpu);
-       struct scpi_data *priv = policy->driver_data;
-       unsigned long rate = clk_get_rate(priv->clk);
+       struct cpufreq_policy *policy;
+       struct scpi_data *priv;
+       unsigned long rate;
+
+       policy = cpufreq_cpu_get_raw(cpu);
+       if (unlikely(!policy))
+               return 0;
+
+       priv = policy->driver_data;
+       rate = clk_get_rate(priv->clk);
 
        return rate / 1000;
 }