public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] driver core: Call pm_runtime_put_sync() only after device_remove()
@ 2023-05-11  7:34 Uwe Kleine-König
  2023-05-11 10:18 ` Rafael J. Wysocki
  0 siblings, 1 reply; 13+ messages in thread
From: Uwe Kleine-König @ 2023-05-11  7:34 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Rafael J. Wysocki; +Cc: linux-kernel, kernel

Many drivers that use runtime PM call pm_runtime_get_sync() or one of
its variants in their remove callback. So calling pm_runtime_put_sync()
directly before calling the remove callback results (under some
conditions) in the driver's suspend routine being called just to resume
it again afterwards.

So delay the pm_runtime_put_sync() call until after device_remove().

Confirmed on a stm32mp157a that doing

	echo 4400e000.can > /sys/bus/platform/drivers/m_can_platform/unbind

(starting with a runtime-pm suspended 4400e000.can) results in one call
less of m_can_runtime_resume() and m_can_runtime_suspend() each after
this change was applied.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
Hello,

side note: To test I added a dev_info() to m_can_runtime_resume() and
m_can_runtime_suspend(). I was surprised that directly after boot I had:

	# dmesg | grep -E '4400e000.can: m_can_runtime_(resume|suspend)' | wc -l
	15

I didn't go down that rabbit hole to debug this.

Best regards
Uwe

 drivers/base/dd.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/base/dd.c b/drivers/base/dd.c
index 9c09ca5c4ab6..d97f6b1486d1 100644
--- a/drivers/base/dd.c
+++ b/drivers/base/dd.c
@@ -1267,10 +1267,10 @@ static void __device_release_driver(struct device *dev, struct device *parent)
 
 		bus_notify(dev, BUS_NOTIFY_UNBIND_DRIVER);
 
-		pm_runtime_put_sync(dev);
-
 		device_remove(dev);
 
+		pm_runtime_put_sync(dev);
+
 		if (dev->bus && dev->bus->dma_cleanup)
 			dev->bus->dma_cleanup(dev);
 
-- 
2.39.2


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

end of thread, other threads:[~2023-05-17  9:55 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-05-11  7:34 [PATCH] driver core: Call pm_runtime_put_sync() only after device_remove() Uwe Kleine-König
2023-05-11 10:18 ` Rafael J. Wysocki
2023-05-11 10:39   ` Uwe Kleine-König
2023-05-11 11:48     ` Johan Hovold
2023-05-11 14:44       ` Rafael J. Wysocki
2023-05-12  7:40         ` Johan Hovold
2023-05-12 14:04           ` Rafael J. Wysocki
2023-05-12 15:00             ` Johan Hovold
2023-05-12 15:04               ` Rafael J. Wysocki
2023-05-12 18:49           ` Uwe Kleine-König
2023-05-17  8:28             ` Johan Hovold
2023-05-17  9:55               ` Marc Kleine-Budde
2023-05-11 14:46       ` Uwe Kleine-König

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