[PATCH 2/4] usb: move scanned status into core

Sascha Hauer s.hauer at pengutronix.de
Thu Jun 20 10:05:23 EDT 2013


A command should not be interested in the internal USB core state, so
move the state handling into the core.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 commands/usb.c         | 10 +++-------
 drivers/usb/core/usb.c |  9 ++++++++-
 include/usb/usb.h      |  2 +-
 3 files changed, 12 insertions(+), 9 deletions(-)

diff --git a/commands/usb.c b/commands/usb.c
index e503065..9aee430 100644
--- a/commands/usb.c
+++ b/commands/usb.c
@@ -22,24 +22,20 @@
 #include <usb/usb.h>
 #include <getopt.h>
 
-static int scanned;
-
 static int do_usb(int argc, char *argv[])
 {
 	int opt;
+	int force = 0;
 
 	while ((opt = getopt(argc, argv, "f")) > 0) {
 		switch (opt) {
 		case 'f':
-			scanned = 0;
+			force = 1;
 			break;
 		}
 	}
 
-	if (!scanned) {
-		usb_rescan();
-		scanned = 1;
-	}
+	usb_rescan(force);
 
 	return 0;
 }
diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
index e232111..07175dc 100644
--- a/drivers/usb/core/usb.c
+++ b/drivers/usb/core/usb.c
@@ -488,12 +488,19 @@ static struct usb_device *usb_alloc_new_device(void)
 	return usbdev;
 }
 
-void usb_rescan(void)
+static int scanned;
+
+void usb_rescan(int force)
 {
 	struct usb_device *dev, *tmp;
 	struct usb_host *host;
 	int ret;
 
+	if (scanned && !force)
+		return;
+
+	scanned = 1;
+
 	list_for_each_entry_safe(dev, tmp, &usb_device_list, list) {
 		list_del(&dev->list);
 		unregister_device(&dev->dev);
diff --git a/include/usb/usb.h b/include/usb/usb.h
index da0090e..2e1498c 100644
--- a/include/usb/usb.h
+++ b/include/usb/usb.h
@@ -248,7 +248,7 @@ int usb_clear_halt(struct usb_device *dev, int pipe);
 int usb_string(struct usb_device *dev, int index, char *buf, size_t size);
 int usb_set_interface(struct usb_device *dev, int interface, int alternate);
 
-void usb_rescan(void);
+void usb_rescan(int force);
 
 /* big endian -> little endian conversion */
 /* some CPUs are already little endian e.g. the ARM920T */
-- 
1.8.3.1




More information about the barebox mailing list