diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2014-07-10 12:26:43 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2014-07-18 14:50:20 +0200 |
commit | 7c8c7e5ff344ffb4df21853101731f7d939a2fdd (patch) | |
tree | 66e0314aa8a872921051d7793940f463eea6e3f5 | |
parent | 9fc0d34763d4e3cdaa9ed05210bfdc23286b65a3 (diff) | |
download | barebox-7c8c7e5ff344ffb4df21853101731f7d939a2fdd.tar.gz barebox-7c8c7e5ff344ffb4df21853101731f7d939a2fdd.tar.xz |
USB: host: simplify usb_new_device
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>
-rw-r--r-- | drivers/usb/core/usb.c | 23 |
1 files changed, 5 insertions, 18 deletions
diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c index 710f611995..4f5c0edded 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 */ |