mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH] driver: base: report driver remove before, not after operation
Date: Thu, 11 Dec 2025 21:37:07 +0100	[thread overview]
Message-ID: <20251211203708.2440188-1-a.fatoum@pengutronix.de> (raw)

Calling pr_report_probe() after the removal is unexpected as for
initcalls and probes, we print before to make hangs or crashes
easier to pinpoint.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 drivers/base/driver.c | 23 ++++++++++++++++++-----
 1 file changed, 18 insertions(+), 5 deletions(-)

diff --git a/drivers/base/driver.c b/drivers/base/driver.c
index 753e06963b16..102e7ea2c0dd 100644
--- a/drivers/base/driver.c
+++ b/drivers/base/driver.c
@@ -659,15 +659,25 @@ int dev_add_alias(struct device *dev, const char *fmt, ...)
 }
 EXPORT_SYMBOL_GPL(dev_add_alias);
 
-bool device_remove(struct device *dev)
+typedef void (*dev_remove_op_t)(struct device *dev);
+
+static dev_remove_op_t get_device_remove(struct device *dev)
 {
 	if (dev->bus && dev->bus->remove)
-		dev->bus->remove(dev);
+		return dev->bus->remove;
 	else if (dev->driver->remove)
-		dev->driver->remove(dev);
+		return dev->driver->remove;
 	else
-		return false; /* nothing to do */
+		return NULL;
+}
 
+bool device_remove(struct device *dev)
+{
+	dev_remove_op_t remove = get_device_remove(dev);
+	if (!remove)
+		return false;  /* nothing to do */
+
+	remove(dev);
 	return true;
 }
 EXPORT_SYMBOL_GPL(device_remove);
@@ -677,8 +687,11 @@ static void devices_shutdown(void)
 	struct device *dev;
 
 	list_for_each_entry(dev, &active_device_list, active) {
-		if (device_remove(dev))
+		dev_remove_op_t remove = get_device_remove(dev);
+		if (remove) {
 			pr_report_probe("%*sremove-> %s\n", 1 * 4, "", dev_name(dev));
+			remove(dev);
+		}
 		dev->driver = NULL;
 	}
 }
-- 
2.47.3




             reply	other threads:[~2025-12-11 20:37 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-11 20:37 Ahmad Fatoum [this message]
2025-12-15  7:20 ` Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20251211203708.2440188-1-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox