]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
powercap: dtpm_cpu: Fix NULL pointer dereference in get_pd_power_uw()
authorSivan Zohar-Kotzer <sivany32@gmail.com>
Tue, 1 Jul 2025 22:13:55 +0000 (01:13 +0300)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Thu, 3 Jul 2025 15:19:37 +0000 (17:19 +0200)
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")
Signed-off-by: Sivan Zohar-Kotzer <sivany32@gmail.com>
Link: https://patch.msgid.link/20250701221355.96916-1-sivany32@gmail.com
[ rjw: Drop an excess empty code line ]
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
drivers/powercap/dtpm_cpu.c

index 6b6f51b215501b36c7cd08871c3ec7f50e13cf37..99390ec1481f83d8db84f4df4a43729965dbbe75 100644 (file)
@@ -96,6 +96,8 @@ static u64 get_pd_power_uw(struct dtpm *dtpm)
        int i;
 
        pd = em_cpu_get(dtpm_cpu->cpu);
+       if (!pd)
+               return 0;
 
        pd_mask = em_span_cpus(pd);