From 7c8c7e5ff344ffb4df21853101731f7d939a2fdd Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Thu, 10 Jul 2014 12:26:43 +0200 Subject: 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 --- 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 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 */ -- cgit v1.2.3