[PATCH v2 2/7] USB: Count detected USB devices independent of dev_index
Sebastian Hesselbarth
sebastian.hesselbarth at gmail.com
Sat Jul 26 08:24:40 PDT 2014
Adding a usb device increases dev_index every time a new device is
allocated. Removing a usb device does not decrease again, of course.
As we print the number of detected usb devices after each usb bus
scan based on dev_index, we cannot trust dev_index here. Keep track
of the correct number of (currently) detected usb devices by
introducing an independent dev_count that gets increased on detect
and decreased on remove.
Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth at gmail.com>
---
To: Sascha Hauer <s.hauer at pengutronix.de>
Cc: Thomas Petazzoni <thomas.petazzoni at free-electrons.com>
Cc: Ezequiel Garcia <ezequiel.garcia at free-electrons.com>
Cc: barebox at lists.infradead.org
---
drivers/usb/core/usb.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
index 2cc338465539..d3bd19be706d 100644
--- a/drivers/usb/core/usb.c
+++ b/drivers/usb/core/usb.c
@@ -66,6 +66,7 @@
#define USB_BUFSIZ 512
+static int dev_count;
static int dev_index;
static int asynch_allowed;
@@ -448,6 +449,7 @@ int usb_new_device(struct usb_device *dev)
dev_add_param_int_ro(&dev->dev, "idProduct",
le16_to_cpu(dev->descriptor->idProduct), "%04x");
list_add_tail(&dev->list, &usb_device_list);
+ dev_count++;
err = 0;
@@ -474,6 +476,7 @@ void usb_remove_device(struct usb_device *usbdev)
usbdev->parent->children[usbdev->portnr - 1] = NULL;
list_del(&usbdev->list);
free(usbdev);
+ dev_count--;
}
struct usb_device *usb_alloc_new_device(void)
@@ -527,7 +530,7 @@ void usb_rescan(void)
continue;
}
- pr_info("%d USB Device(s) found\n", dev_index);
+ pr_info("%d USB Device(s) found\n", dev_count);
}
/*
--
2.0.0
More information about the barebox
mailing list