[PATCH v3 01/17] dm: Move flags_remove() check before child removal

Simon Glass sjg at chromium.org
Sat Feb 28 21:19:49 CET 2026


From: Simon Glass <simon.glass at canonical.com>

Move the flags_remove() call before device_chld_remove() and save the
result in a separate variable. This is just a refactoring with no
behaviour change, preparing for the next commit which needs to know
whether the parent will be removed before deciding how to remove its
children.

Signed-off-by: Simon Glass <simon.glass at canonical.com>
---

(no changes since v1)

 drivers/core/device-remove.c | 23 ++++++++++++-----------
 1 file changed, 12 insertions(+), 11 deletions(-)

diff --git a/drivers/core/device-remove.c b/drivers/core/device-remove.c
index 437080ed778..03ef49c4db0 100644
--- a/drivers/core/device-remove.c
+++ b/drivers/core/device-remove.c
@@ -198,7 +198,7 @@ static int flags_remove(uint flags, uint drv_flags)
 int device_remove(struct udevice *dev, uint flags)
 {
 	const struct driver *drv;
-	int ret;
+	int ret, cret;
 
 	if (!dev)
 		return -EINVAL;
@@ -210,6 +210,14 @@ int device_remove(struct udevice *dev, uint flags)
 	if (ret)
 		return ret;
 
+	/*
+	 * Remove the device if called with the "normal" remove flag set,
+	 * or if the remove flag matches any of the drivers remove flags
+	 */
+	drv = dev->driver;
+	assert(drv);
+	cret = flags_remove(flags, drv->flags);
+
 	/*
 	 * If the child returns EKEYREJECTED, continue. It just means that it
 	 * didn't match the flags.
@@ -218,17 +226,10 @@ int device_remove(struct udevice *dev, uint flags)
 	if (ret && ret != -EKEYREJECTED)
 		return ret;
 
-	/*
-	 * Remove the device if called with the "normal" remove flag set,
-	 * or if the remove flag matches any of the drivers remove flags
-	 */
-	drv = dev->driver;
-	assert(drv);
-	ret = flags_remove(flags, drv->flags);
-	if (ret) {
+	if (cret) {
 		log_debug("%s: When removing: flags=%x, drv->flags=%x, err=%d\n",
-			  dev->name, flags, drv->flags, ret);
-		return ret;
+			  dev->name, flags, drv->flags, cret);
+		return cret;
 	}
 
 	ret = uclass_pre_remove_device(dev);
-- 
2.43.0



More information about the U-Boot mailing list