linux/drivers/base/power
Jiakai Xu 31064374d2 PM: sleep: Use complete() in device_pm_sleep_init()
[ Upstream commit 3855941f1e ]

Replace complete_all() with complete() in device_pm_sleep_init() to allow
it to be called in atomic contexts without triggering a false-positive
WARNING from lockdep_assert_RT_in_threaded_ctx() when
CONFIG_PROVE_RAW_LOCK_NESTING is enabled.

device_pm_sleep_init() may be called during device initialization while
holding a raw_spinlock (e.g., from within device_initialize()), and
complete_all() is unsafe in atomic contexts on PREEMPT_RT kernels.
complete(), which is safe to call from any context, is sufficient here.

complete_all() sets the completion count to UINT_MAX/2 (permanently
signaled), while complete() increments it by 1. Since no threads can be
waiting during device initialization, both are functionally equivalent.
The completion is always reinitialized via reinit_completion() in
dpm_clear_async_state() before each suspend/resume cycle.

However, changing to complete() introduces a potential deadlock for
devices with no PM support (dev->power.no_pm = true). Such devices are
never added to the dpm_list and never go through dpm_clear_async_state(),
so their completion is never reinitialized. A parent device waiting on a
no_pm child across multiple suspend phases would consume the single-use
token in the first phase and block forever in the second.

Fix this by adding an early return in dpm_wait() when dev->power.no_pm is
set, since no_pm devices do not participate in system suspend/resume.

Fixes: 152e1d5920 ("PM: Prevent waiting forever on asynchronous resume after failing suspend")
Signed-off-by: Jiakai Xu <xujiakai24@mails.ucas.ac.cn>
[ rjw: Subject adjustment ]
Link: https://patch.msgid.link/20260523022314.2657232-1-xujiakai24@mails.ucas.ac.cn
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
History 2026-07-24 15:51:30 +02:00
..
clock_ops.c PM: runtime: add devm_pm_clk_create helper 2021-08-26 11:28:07 -07:00
common.c PM / Domains: Introduce dev_pm_domain_start() 2019-11-13 11:41:50 +01:00
domain.c pmdomain: core: Fix detach procedure for virtual devices in genpd 2026-06-19 13:33:44 +02:00
domain_governor.c pmdomain: governor: Consider CPU latency tolerance from pm_domain_cpu_gov 2025-08-28 16:24:00 +02:00
generic_ops.c drivers: base: power: add proper SPDX identifiers on files that did not have them. 2019-04-04 20:03:40 +02:00
main.c PM: sleep: Use complete() in device_pm_sleep_init() 2026-07-24 15:51:30 +02:00
Makefile PM / QoS: Initial kunit test 2019-11-29 12:04:49 +01:00
power.h PM: sleep: wakeirq: fix wake irq arming 2023-08-11 15:14:00 +02:00
qos-test.c kunit: allow kunit tests to be loaded as a module 2020-01-09 16:42:29 -07:00
qos.c PM / QoS: Restore DEV_PM_QOS_MIN/MAX_FREQUENCY 2019-11-29 12:04:50 +01:00
runtime.c PM: runtime: Fix a race condition related to device removal 2026-04-18 10:33:21 +02:00
sysfs.c drivers core: Miscellaneous changes for sysfs_emit 2020-10-02 13:12:07 +02:00
trace.c rtc: Check return value from mc146818_get_time() 2022-04-13 20:59:14 +02:00
wakeirq.c PM: sleep: wakeirq: harden dev_pm_clear_wake_irq() against races 2026-03-04 07:19:23 -05:00
wakeup.c PM: wakeup: Handle empty list in wakeup_sources_walk_start() 2026-03-04 07:19:22 -05:00
wakeup_stats.c PM: wakeup: remove redundant assignment to variable retval 2021-04-22 15:22:38 +02:00