Skip to contentSkip to conversation

powercap: dtpm_cpu: Fix NULL pointer dereference in get_pd_power_uw()

PATCH Applied Sivan Zohar-Kotzer 2 participants 2 messages Jul 1, 2025 – Jul 3, 2025

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

PATCH 1/1 powercap: dtpm_cpu: Fix NULL pointer dereference in get_pd_power_uw()

The get_pd_power_uw() function can crash with a NULL pointer dereference when em_cpu_get() returns NULL. This occurs when a CPU becomes impossible during runtime, causing get_cpu_device() to return NULL, which propagates through em_cpu_get() and leads to a crash when em_span_cpus() dereferences the NULL pointer.

Add a NULL check after em_cpu_get() and return 0 if unavailable, matching the existing fallback behavior in __dtpm_cpu_setup().

Fixes eb82bace8931 ("powercap/drivers/dtpm: Scale the power with the load")
---
 drivers/powercap/dtpm_cpu.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/powercap/dtpm_cpu.c +3 -0
index 6b6f51b21550..0f1c19308f46 100644
@@ -97,6 +97,9 @@ static u64 get_pd_power_uw(struct dtpm *dtpm)
 
 	pd = em_cpu_get(dtpm_cpu->cpu);
 
+	if (!pd)
+		return 0;
+
 	pd_mask = em_span_cpus(pd);
 
 	freq = cpufreq_quick_get(dtpm_cpu->cpu);
Signature · 1 line
2.45.2
maintainer Applied
#1 lore raw
Quoted 21 lines · Sivan Zohar-Kotzer

The get_pd_power_uw() function can crash with a NULL pointer dereference when em_cpu_get() returns NULL. This occurs when a CPU becomes impossible during runtime, causing get_cpu_device() to return NULL, which propagates through em_cpu_get() and leads to a crash when em_span_cpus() dereferences the NULL pointer.

Add a NULL check after em_cpu_get() and return 0 if unavailable, matching the existing fallback behavior in __dtpm_cpu_setup().

Fixes eb82bace8931 ("powercap/drivers/dtpm: Scale the power with the load")
---
 drivers/powercap/dtpm_cpu.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/powercap/dtpm_cpu.c +0 -0
index 6b6f51b21550..0f1c19308f46 100644

drivers/powercap/dtpm_cpu.c static u64 get_pd_power_uw(struct dtpm *dtpm)

Quoted 10 lines
drivers/powercap/dtpm_cpu.c +3 -1
@@ -97,6 +97,9 @@ static u64 get_pd_power_uw(struct dtpm *dtpm)
 
        pd = em_cpu_get(dtpm_cpu->cpu);
 
+       if (!pd)
+               return 0;
+
        pd_mask = em_span_cpus(pd);
 
        freq = cpufreq_quick_get(dtpm_cpu->cpu);
--

Applied as 6.17 material, thanks!