[PATCH 2/5] driver core: do not always lock parent in shutdown
From: David Jeffery
Date: Thu Mar 19 2026 - 10:14:34 EST
Don't lock a parent device unless it is needed in device_shutdown. This
is in preparation for making device shutdown asynchronous, when it will
be needed to allow children of a common parent to shut down
simultaneously.
Signed-off-by: Stuart Hayes <stuart.w.hayes@xxxxxxxxx>
Signed-off-by: David Jeffery <djeffery@xxxxxxxxxx>
Tested-by: Laurence Oberman <loberman@xxxxxxxxxx>
---
drivers/base/core.c | 23 ++++++++++++++---------
1 file changed, 14 insertions(+), 9 deletions(-)
diff --git a/drivers/base/core.c b/drivers/base/core.c
index 10586298e18b..2e9094f5c5aa 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -4782,13 +4782,8 @@ int device_change_owner(struct device *dev, kuid_t kuid, kgid_t kgid)
return error;
}
-static void shutdown_one_device(struct device *dev)
+static void __shutdown_one_device(struct device *dev)
{
- struct device *parent = dev->parent;
-
- /* hold lock to avoid race with probe/release */
- if (parent)
- device_lock(parent);
device_lock(dev);
/* Don't allow any more runtime suspends */
@@ -4811,10 +4806,20 @@ static void shutdown_one_device(struct device *dev)
}
device_unlock(dev);
- if (parent)
- device_unlock(parent);
+}
- put_device(parent);
+static void shutdown_one_device(struct device *dev)
+{
+ /* hold lock to avoid race with probe/release */
+ if (dev->parent && dev->bus && dev->bus->need_parent_lock) {
+ device_lock(dev->parent);
+ __shutdown_one_device(dev);
+ device_unlock(dev->parent);
+ } else {
+ __shutdown_one_device(dev);
+ }
+
+ put_device(dev->parent);
put_device(dev);
}
--
2.53.0