aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/core/hub.c
diff options
context:
space:
mode:
authorHuajun Li <huajun.li.lee@gmail.com>2012-03-12 09:00:19 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2012-03-13 17:24:07 -0400
commit8816230e13d0c3c6ba51916d20e6d204646abf03 (patch)
tree3b9c29e8e07490fa6914fbe75c7dcfe95b84c14c /drivers/usb/core/hub.c
parent90221170bfe101de59a05910b4cb6d6e5de046b1 (diff)
USB: dynamically allocate usb_device children pointers instead of using a fix array
Non-hub device has no child, and even a real USB hub has ports far less than USB_MAXCHILDREN, so there is no need using a fix array for child devices, just allocate it dynamically according real port number. Signed-off-by: Huajun Li <huajun.li.lee@gmail.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/usb/core/hub.c')
-rw-r--r--drivers/usb/core/hub.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
index 72c51cdce906..28664eb7f555 100644
--- a/drivers/usb/core/hub.c
+++ b/drivers/usb/core/hub.c
@@ -1047,8 +1047,10 @@ static int hub_configure(struct usb_hub *hub,
1047 dev_info (hub_dev, "%d port%s detected\n", hdev->maxchild, 1047 dev_info (hub_dev, "%d port%s detected\n", hdev->maxchild,
1048 (hdev->maxchild == 1) ? "" : "s"); 1048 (hdev->maxchild == 1) ? "" : "s");
1049 1049
1050 hdev->children = kzalloc(hdev->maxchild *
1051 sizeof(struct usb_device *), GFP_KERNEL);
1050 hub->port_owners = kzalloc(hdev->maxchild * sizeof(void *), GFP_KERNEL); 1052 hub->port_owners = kzalloc(hdev->maxchild * sizeof(void *), GFP_KERNEL);
1051 if (!hub->port_owners) { 1053 if (!hdev->children || !hub->port_owners) {
1052 ret = -ENOMEM; 1054 ret = -ENOMEM;
1053 goto fail; 1055 goto fail;
1054 } 1056 }
@@ -1279,7 +1281,8 @@ static unsigned highspeed_hubs;
1279 1281
1280static void hub_disconnect(struct usb_interface *intf) 1282static void hub_disconnect(struct usb_interface *intf)
1281{ 1283{
1282 struct usb_hub *hub = usb_get_intfdata (intf); 1284 struct usb_hub *hub = usb_get_intfdata(intf);
1285 struct usb_device *hdev = interface_to_usbdev(intf);
1283 1286
1284 /* Take the hub off the event list and don't let it be added again */ 1287 /* Take the hub off the event list and don't let it be added again */
1285 spin_lock_irq(&hub_event_lock); 1288 spin_lock_irq(&hub_event_lock);
@@ -1301,6 +1304,7 @@ static void hub_disconnect(struct usb_interface *intf)
1301 highspeed_hubs--; 1304 highspeed_hubs--;
1302 1305
1303 usb_free_urb(hub->urb); 1306 usb_free_urb(hub->urb);
1307 kfree(hdev->children);
1304 kfree(hub->port_owners); 1308 kfree(hub->port_owners);
1305 kfree(hub->descriptor); 1309 kfree(hub->descriptor);
1306 kfree(hub->status); 1310 kfree(hub->status);
@@ -1676,7 +1680,7 @@ void usb_disconnect(struct usb_device **pdev)
1676 usb_lock_device(udev); 1680 usb_lock_device(udev);
1677 1681
1678 /* Free up all the children before we remove this device */ 1682 /* Free up all the children before we remove this device */
1679 for (i = 0; i < USB_MAXCHILDREN; i++) { 1683 for (i = 0; i < udev->maxchild; i++) {
1680 if (udev->children[i]) 1684 if (udev->children[i])
1681 usb_disconnect(&udev->children[i]); 1685 usb_disconnect(&udev->children[i]);
1682 } 1686 }