mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
To: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>,
	Sascha Hauer <s.hauer@pengutronix.de>
Cc: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>,
	barebox@lists.infradead.org
Subject: [PATCH 2/6] USB: Count detected USB devices independent of dev_index
Date: Thu, 24 Jul 2014 15:28:42 +0200	[thread overview]
Message-ID: <1406208526-24261-3-git-send-email-sebastian.hesselbarth@gmail.com> (raw)
In-Reply-To: <1406208526-24261-1-git-send-email-sebastian.hesselbarth@gmail.com>

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 alloc
and decreased on remove.

Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
---
To: Sascha Hauer <s.hauer@pengutronix.de>
Cc: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
Cc: Ezequiel Garcia <ezequiel.garcia@free-electrons.com>
Cc: barebox@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


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  parent reply	other threads:[~2014-07-24 13:29 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-24 13:28 [PATCH 0/6] Minor USB fixes and xHCI driver Sebastian Hesselbarth
2014-07-24 13:28 ` [PATCH 1/6] USB: Fix stale usb devices in usb_device_list Sebastian Hesselbarth
2014-07-24 16:09   ` Sebastian Hesselbarth
2014-07-24 18:51     ` Sebastian Hesselbarth
2014-07-24 13:28 ` Sebastian Hesselbarth [this message]
2014-07-24 13:28 ` [PATCH 3/6] USB: EHCI: use min3 from Linux Sebastian Hesselbarth
2014-07-24 13:28 ` [PATCH 4/6] include: import {lower,upper}_32_bits helpers Sebastian Hesselbarth
2014-07-24 13:28 ` [PATCH 5/6] USB: host: add xHCI HCD, Hub, and platform driver Sebastian Hesselbarth
2014-07-24 13:46   ` Sebastian Hesselbarth
2014-07-24 13:28 ` [PATCH 6/6] USB: host: add xHCI PCI driver Sebastian Hesselbarth
2014-07-24 19:11 ` [PATCH 0/6] Minor USB fixes and xHCI driver Sebastian Hesselbarth
2014-07-25  7:32 ` Sascha Hauer
2014-07-25 14:40   ` Sebastian Hesselbarth
2014-07-25 15:34     ` Sebastian Hesselbarth

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1406208526-24261-3-git-send-email-sebastian.hesselbarth@gmail.com \
    --to=sebastian.hesselbarth@gmail.com \
    --cc=barebox@lists.infradead.org \
    --cc=s.hauer@pengutronix.de \
    --cc=thomas.petazzoni@free-electrons.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox