From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: ske@pengutronix.de, Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 1/3] driver: make CONFIG_DEBUG_PROBES more useful for removal
Date: Thu, 15 Feb 2024 11:33:51 +0100 [thread overview]
Message-ID: <20240215103353.2799723-1-a.fatoum@pengutronix.de> (raw)
When CONFIG_DEBUG_PROBES is enabled, barebox will print a message on
every device probe and removal. Unfortunately, the removal prints are not
very useful, because the removal happens in the bus remove function,
which is often a no-op, but that's not known to driver core.
To make this a bit more useful, let's allow skipping bus remove
functions like Linux does and only print that a remove is happening if
either a bus or driver remove function is available.
At present, this doesn't change much, but the follow-up commit will drop
bus remove functions that only call the driver remove function, which
will shorten the CONFIG_DEBUG_PROBES output on shutdown a fair bit.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
commands/devunbind.c | 14 +++++++++-----
drivers/base/driver.c | 28 ++++++++++++++++++----------
include/driver.h | 10 ++++++++++
3 files changed, 37 insertions(+), 15 deletions(-)
diff --git a/commands/devunbind.c b/commands/devunbind.c
index dab7f834db9f..d30193b28527 100644
--- a/commands/devunbind.c
+++ b/commands/devunbind.c
@@ -20,9 +20,14 @@ static int do_devunbind(int argc, char *argv[])
break;
case 'l':
list_for_each_entry(dev, &active_device_list, active) {
+ void *rm_dev;
+
BUG_ON(!dev->driver);
- if (dev->bus->remove)
- printf("%pS(%s, %s)\n", dev->bus->remove,
+
+ rm_dev = dev->bus->remove ?: dev->driver->remove;
+
+ if (rm_dev)
+ printf("%pS(%s, %s)\n", rm_dev,
dev->driver->name, dev_name(dev));
}
return 0;
@@ -47,13 +52,12 @@ static int do_devunbind(int argc, char *argv[])
continue;
}
- if (!dev->driver || !dev->bus->remove) {
- printf("skipping unbound %s\n", argv[i]);
+ if (!device_remove(dev)) {
+ printf("no remove callback registered for %s\n", argv[i]);
ret = COMMAND_ERROR;
continue;
}
- dev->bus->remove(dev);
dev->driver = NULL;
list_del(&dev->active);
}
diff --git a/drivers/base/driver.c b/drivers/base/driver.c
index 6548aec9b27b..8bd187eef57f 100644
--- a/drivers/base/driver.c
+++ b/drivers/base/driver.c
@@ -280,7 +280,7 @@ int unregister_device(struct device *old_dev)
dev_remove_parameters(old_dev);
if (old_dev->driver)
- old_dev->bus->remove(old_dev);
+ device_remove(old_dev);
list_for_each_entry_safe(alias, at, &device_alias_list, list) {
if(alias->dev == old_dev)
@@ -432,7 +432,7 @@ void unregister_driver(struct driver *drv)
bus_for_each_device(drv->bus, dev) {
if (dev->driver == drv) {
- drv->bus->remove(dev);
+ device_remove(dev);
dev->driver = NULL;
list_del(&dev->active);
INIT_LIST_HEAD(&dev->active);
@@ -641,19 +641,27 @@ int dev_add_alias(struct device *dev, const char *fmt, ...)
}
EXPORT_SYMBOL_GPL(dev_add_alias);
+bool device_remove(struct device *dev)
+{
+ if (dev->bus && dev->bus->remove)
+ dev->bus->remove(dev);
+ else if (dev->driver->remove)
+ dev->driver->remove(dev);
+ else
+ return false; /* nothing to do */
+
+ return true;
+}
+EXPORT_SYMBOL_GPL(device_remove);
+
static void devices_shutdown(void)
{
struct device *dev;
- int depth = 0;
list_for_each_entry(dev, &active_device_list, active) {
- if (dev->bus->remove) {
- depth++;
- pr_report_probe("%*sremove-> %s\n", depth * 4, "", dev_name(dev));
- dev->bus->remove(dev);
- dev->driver = NULL;
- depth--;
- }
+ if (device_remove(dev))
+ pr_report_probe("%*sremove-> %s\n", 1 * 4, "", dev_name(dev));
+ dev->driver = NULL;
}
}
devshutdown_exitcall(devices_shutdown);
diff --git a/include/driver.h b/include/driver.h
index 638426b9606a..b7c950620bca 100644
--- a/include/driver.h
+++ b/include/driver.h
@@ -166,6 +166,16 @@ int register_device(struct device *);
*/
int device_probe(struct device *dev);
+/**
+ * device_remove - Remove a device from its bus and driver
+ *
+ * @dev: Device
+ *
+ * Returns true if there was any bus or driver specific removal
+ * code that was executed and false if the function was a no-op.
+ */
+bool device_remove(struct device *dev);
+
/* detect devices attached to this device (cards, disks,...) */
int device_detect(struct device *dev);
int device_detect_by_name(const char *devname);
--
2.39.2
next reply other threads:[~2024-02-15 10:36 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-15 10:33 Ahmad Fatoum [this message]
2024-02-15 10:33 ` [PATCH 2/3] drivers: drop simple bus remove in favor of common implementation Ahmad Fatoum
2024-02-15 10:33 ` [PATCH 3/3] firmware: arm_scmi: call device driver remove if defined Ahmad Fatoum
2024-02-16 11:59 ` [PATCH 1/3] driver: make CONFIG_DEBUG_PROBES more useful for removal 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=20240215103353.2799723-1-a.fatoum@pengutronix.de \
--to=a.fatoum@pengutronix.de \
--cc=barebox@lists.infradead.org \
--cc=ske@pengutronix.de \
/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