[PATCH 3/9] driver core: warn should device_move try to move a need_parent_lock device

From: David Jeffery

Date: Fri Aug 21 2026 - 10:26:05 EST


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@xxxxxxxxxx>
Tested-by: Laurence Oberman <loberman@xxxxxxxxxx>
---
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