summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAhmad Fatoum <a.fatoum@pengutronix.de>2024-02-15 11:33:51 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2024-02-16 12:59:47 +0100
commit4d515afe56eb337b1118782f53b61b903a962fbd (patch)
tree6662242d092285da7bdd30df1960868973997de3
parent82a51038356dc518439a2153ca95482f1f543dc6 (diff)
downloadbarebox-4d515afe56eb337b1118782f53b61b903a962fbd.tar.gz
barebox-4d515afe56eb337b1118782f53b61b903a962fbd.tar.xz
driver: make CONFIG_DEBUG_PROBES more useful for removal
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> Link: https://lore.barebox.org/20240215103353.2799723-1-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
-rw-r--r--commands/devunbind.c14
-rw-r--r--drivers/base/driver.c28
-rw-r--r--include/driver.h10
3 files changed, 37 insertions, 15 deletions
diff --git a/commands/devunbind.c b/commands/devunbind.c
index dab7f834db..d30193b285 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 6548aec9b2..8bd187eef5 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 638426b960..b7c950620b 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);