Skip to content

powercap: dtpm: Guard against missing energy model in dtpm callbacks

Elazar Leibovich linux-pm lkml 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest2 patches 1 replyIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/2powercap: dtpm_cpu: Guard em_cpu_get() against NULL return in sysfs callbacksdrivers/powercap/dtpm_cpu.c+6 -01 reply
2/2powercap: dtpm_devfreq: Guard em_pd_get() against NULL return in callbacksdrivers/powercap/dtpm_devfreq.c+9 -00 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [PATCH 0/2] powercap: dtpm: Guard against missing energy model in dtpm callbacks

The dtpm_cpu and dtpm_devfreq powercap drivers dereference the perf domain returned by em_cpu_get()/em_pd_get() without checking it for NULL. When the energy model is absent - for instance when a CPU becomes impossible at runtime so get_cpu_device() returns NULL, or when the device EM was never registered or has already been unregistered - the dtpm callbacks, several of which are reachable directly from sysfs via the powercap zone attributes, crash on a NULL pointer dereference.

Add the missing NULL checks, mirroring the guard that already exists in get_pd_power_uw() since commit 46dc57406887 ("powercap: dtpm_cpu: Fix NULL pointer dereference in get_pd_power_uw()").

Note these patches only handle a perf domain that is already gone when the callback starts. A callback racing with em_dev_unregister_perf_domain() can still observe a non-NULL perf domain that is freed underneath it, because only the EM perf state table is RCU-protected, not struct em_perf_domain itself. Closing that race needs RCU lifetime guarantees from the EM core plus holding rcu_read_lock() across the perf domain access in the readers; this will be addressed in future patches.

Sivan Zohar-Kotzer (2):
powercap: dtpm_cpu: Guard em_cpu_get() against NULL return in sysfs
callbacks
powercap: dtpm_devfreq: Guard em_pd_get() against NULL return in
callbacks

 drivers/powercap/dtpm_cpu.c     | 6 ++++++
 drivers/powercap/dtpm_devfreq.c | 9 +++++++++
 2 files changed, 15 insertions(+)
Signature · 1 line
2.50.1 (Apple Git-155)