Skip to contentSkip to conversation

cpufreq: scpi: Fix null-ptr-deref in scpi_cpufreq_get_rate()

PATCH In review Henry Martin 1 participant 2 messages Apr 9, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 2/2 cpufreq: scpi: Fix null-ptr-deref in scpi_cpufreq_get_rate()

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")

---
V1 -> V2: Use if (unlikely(!policy)) instead of if (!policy)

 drivers/cpufreq/scpi-cpufreq.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)
drivers/cpufreq/scpi-cpufreq.c +10 -3
index 17cda84f00df..dcbb0ae7dd47 100644
@@ -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;
 }
Signature · 1 line
2.34.1
#1 lore raw

Sorry for the noise - please disregard this patch as it was sent in error.

Quoted 40 lines · Henry Martin <[email protected]> 于2025年4月9日周三 20:45写道:

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")

---
V1 -> V2: Use if (unlikely(!policy)) instead of if (!policy)

 drivers/cpufreq/scpi-cpufreq.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)
drivers/cpufreq/scpi-cpufreq.c +10 -4
index 17cda84f00df..dcbb0ae7dd47 100644
@@ -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;
 }
--

2.34.1