[PATCH 3/9] driver core: warn should device_move try to move a need_parent_lock device
David Jeffery
djeffery at redhat.com
Fri Aug 21 07:24:08 PDT 2026
Currently, no device has need_parent_lock set and is moved by
device_move. need_parent_lock is only set by the usb bus and very
few device types ever use device_move.
Add a warning to device_move to catch should it ever be used on a
device with need_parent_lock set. The combination would break
the immutable relationship needed between parent and child for
need_parent_lock when locking and unlocking both.
Signed-off-by: David Jeffery <djeffery at redhat.com>
Tested-by: Laurence Oberman <loberman at redhat.com>
---
drivers/base/core.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/drivers/base/core.c b/drivers/base/core.c
index bd9c2921e326..75f5931165a8 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -4712,6 +4712,14 @@ int device_move(struct device *dev, struct device *new_parent,
if (!dev)
return -EINVAL;
+ /*
+ * device_move() should not be used on devices with need_parent_lock
+ * set. Concurrent reparenting will violate the immutable
+ * relationship needed while locking and unlocking both parent and
+ * child.
+ */
+ WARN_ON(dev->bus && dev->bus->need_parent_lock);
+
device_pm_lock();
new_parent = get_device(new_parent);
new_parent_kobj = get_device_parent(dev, new_parent);
--
2.55.0
More information about the kexec
mailing list