From 8938752dd883b03003701264fcb2bf96522e728f Mon Sep 17 00:00:00 2001 From: Sebastian Hesselbarth Date: Sat, 26 Jul 2014 17:24:40 +0200 Subject: USB: Count detected USB devices independent of dev_index 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 Signed-off-by: Sascha Hauer --- 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 201b84e0ee..7307a6f103 100644 --- a/drivers/usb/core/usb.c +++ b/drivers/usb/core/usb.c @@ -65,6 +65,7 @@ #define USB_BUFSIZ 512 +static int dev_count; static int dev_index; static int asynch_allowed; @@ -447,6 +448,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; @@ -473,6 +475,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) @@ -526,7 +529,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); } /* -- cgit v1.2.3