[PATCH 1/3] driver: make CONFIG_DEBUG_PROBES more useful for removal

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxxxx>
---
 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





[Index of Archives]     [Linux Embedded]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux