mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH 03/12] USB: host: simplify usb_new_device
Date: Sat, 19 Jul 2014 11:15:58 +0200	[thread overview]
Message-ID: <1405761367-23724-4-git-send-email-s.hauer@pengutronix.de> (raw)
In-Reply-To: <1405761367-23724-1-git-send-email-s.hauer@pengutronix.de>

usb_new_device tries to find the port number it is attached to
by iterating over the parents children and using the loop counter
index as port number. Instead, just use the portnr field in struct
usb_device.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/usb/core/usb.c | 23 +++++------------------
 1 file changed, 5 insertions(+), 18 deletions(-)

diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
index 710f611..4f5c0ed 100644
--- a/drivers/usb/core/usb.c
+++ b/drivers/usb/core/usb.c
@@ -297,7 +297,6 @@ static int usb_new_device(struct usb_device *dev)
 	int tmp;
 	void *buf;
 	struct usb_device_descriptor *desc;
-	int port = -1;
 	struct usb_device *parent = dev->parent;
 	unsigned short portstatus;
 	char str[16];
@@ -338,24 +337,10 @@ static int usb_new_device(struct usb_device *dev)
 
 	/* find the port number we're at */
 	if (parent) {
-		int j;
-
-		for (j = 0; j < parent->maxchild; j++) {
-			if (parent->children[j] == dev) {
-				port = j;
-				break;
-			}
-		}
-		if (port < 0) {
-			printf("%s: cannot locate device's port.\n", __func__);
-			err = -ENODEV;
-			goto err_out;
-		}
-
 		/* reset the port for the second time */
-		err = hub_port_reset(dev->parent, port, &portstatus);
+		err = hub_port_reset(dev->parent, dev->portnr - 1, &portstatus);
 		if (err < 0) {
-			printf("\n     Couldn't reset port %i\n", port);
+			printf("\n     Couldn't reset port %i\n", dev->portnr);
 			goto err_out;
 		}
 	}
@@ -433,7 +418,7 @@ static int usb_new_device(struct usb_device *dev)
 			   dev->serial, sizeof(dev->serial));
 
 	if (parent) {
-		sprintf(dev->dev.name, "%s-%d", parent->dev.name, port);
+		sprintf(dev->dev.name, "%s-%d", parent->dev.name, dev->portnr - 1);
 	} else {
 		sprintf(dev->dev.name, "usb%d", dev->host->busnum);
 	}
@@ -1108,6 +1093,8 @@ static void usb_hub_port_connect_change(struct usb_device *dev, int port)
 
 	dev->children[port] = usb;
 	usb->parent = dev;
+	usb->portnr = port + 1;
+
 	/* Run it through the hoops (find a driver, etc) */
 	if (usb_new_device(usb)) {
 		/* Woops, disable the port */
-- 
2.0.1


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

  parent reply	other threads:[~2014-07-19  9:16 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-19  9:15 USB Host patches Sascha Hauer
2014-07-19  9:15 ` [PATCH 01/12] USB: i.MX chipidea: Implement OTG support for the poor Sascha Hauer
2014-07-19  9:15 ` [PATCH 02/12] commands: usb: add tree view capability Sascha Hauer
2014-07-19  9:15 ` Sascha Hauer [this message]
2014-07-19  9:15 ` [PATCH 04/12] USB: host: hub: Turn into a driver Sascha Hauer
2014-07-19  9:16 ` [PATCH 05/12] USB: host: fixup USB device hierarchy Sascha Hauer
2014-07-19  9:16 ` [PATCH 06/12] USB: host: hub: Use dev_dbg Sascha Hauer
2014-07-19  9:16 ` [PATCH 07/12] USB: host: hub: Use usb_hub_power_on from U-Boot Sascha Hauer
2014-07-19  9:16 ` [PATCH 08/12] USB: host: factor out port configuration to separate function Sascha Hauer
2014-07-19  9:16 ` [PATCH 09/12] USB: host: hub: only configure hub once Sascha Hauer
2014-07-19  9:16 ` [PATCH 10/12] USB: host: implement usb_remove_device Sascha Hauer
2014-07-19  9:16 ` [PATCH 11/12] USB: host: detect port change only once in usb_hub_configure_port Sascha Hauer
2014-07-19  9:16 ` [PATCH 12/12] USB: host: drop force rescan Sascha Hauer

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=1405761367-23724-4-git-send-email-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /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