public inbox for linux-pm@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] PM: sleep: core: Set is_prepared to false before checking direct_complete
@ 2025-02-11  3:44 Xu Yang
  2025-02-11  6:43 ` Greg KH
  2025-02-12 20:55 ` Rafael J. Wysocki
  0 siblings, 2 replies; 6+ messages in thread
From: Xu Yang @ 2025-02-11  3:44 UTC (permalink / raw)
  To: rafael, len.brown, pavel, gregkh, dakr, stern; +Cc: linux-pm, imx, jun.li

Currently, if power.no_callbacks is true for a device, device_prepare()
will also set power.direct_complete to true. When device_resume() check
power.direct_complete, setting power.is_prepared will be skipped if it
can directly complete. This will cause a warning when add new devices
during resume() stage.

Although power.is_prepared should be cleared in complete() state, commit
(f76b168b6f11 PM: Rename dev_pm_info.in_suspend to is_prepared) allow
clear it in earlier resume() stage. However, we need set is_prepared to
false before checking direct_complete after including direct complete
support.

Take USB as example:
The usb_interface is such a device which setting power.no_callbacks to
true. Then if the user call usb_set_interface() during resume() stage,
the kernel will print below warning since the system will create and
add ep devices.

[  186.461414] usb 1-1: reset high-speed USB device number 3 using ci_hdrc
[  187.102681]  ep_81: PM: parent 1-1:1.1 should not be sleeping
[  187.105010] PM: resume devices took 0.936 seconds

Fixes: aae4518b3124 ("PM / sleep: Mechanism to avoid resuming runtime-suspended devices unnecessarily")
Signed-off-by: Xu Yang <xu.yang_2@nxp.com>
---
 drivers/base/power/main.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/base/power/main.c b/drivers/base/power/main.c
index 40e1d8d8a589..69d0f9ca7051 100644
--- a/drivers/base/power/main.c
+++ b/drivers/base/power/main.c
@@ -929,6 +929,12 @@ static void device_resume(struct device *dev, pm_message_t state, bool async)
 	if (dev->power.syscore)
 		goto Complete;
 
+	/*
+	 * This is a fib.  But we'll allow new children to be added below
+	 * a resumed device, even if the device hasn't been completed yet.
+	 */
+	dev->power.is_prepared = false;
+
 	if (dev->power.direct_complete) {
 		/* Match the pm_runtime_disable() in device_suspend(). */
 		pm_runtime_enable(dev);
@@ -941,12 +947,6 @@ static void device_resume(struct device *dev, pm_message_t state, bool async)
 	dpm_watchdog_set(&wd, dev);
 	device_lock(dev);
 
-	/*
-	 * This is a fib.  But we'll allow new children to be added below
-	 * a resumed device, even if the device hasn't been completed yet.
-	 */
-	dev->power.is_prepared = false;
-
 	if (!dev->power.is_suspended)
 		goto Unlock;
 
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2025-02-14  9:01 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-11  3:44 [PATCH] PM: sleep: core: Set is_prepared to false before checking direct_complete Xu Yang
2025-02-11  6:43 ` Greg KH
2025-02-12 20:55 ` Rafael J. Wysocki
2025-02-13 10:53   ` Xu Yang
2025-02-13 21:20     ` Rafael J. Wysocki
2025-02-14  8:58       ` Xu Yang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox