powercap: dtpm_cpu: Fix NULL pointer dereference in get_pd_power_uw()
Subsystems (2)
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().
--- drivers/powercap/dtpm_cpu.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/powercap/dtpm_cpu.c +3 -0
@@ -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
Quoted 21 lines · Sivan Zohar-Kotzer
The
get_pd_power_uw()function can crash with a NULL pointer dereference whenem_cpu_get()returns NULL. This occurs when a CPU becomes impossible during runtime, causingget_cpu_device()to return NULL, which propagates throughem_cpu_get()and leads to a crash whenem_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")Signed-off-by Sivan Zohar-Kotzer <[email protected]>--- drivers/powercap/dtpm_cpu.c | 3 +++ 1 file changed, 3 insertions(+)drivers/powercap/dtpm_cpu.c +0
-0
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!