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>hifive-unleashed-5.1
parent
90221170bf
commit
8816230e13
|
@ -1047,8 +1047,10 @@ static int hub_configure(struct usb_hub *hub,
|
||||||
dev_info (hub_dev, "%d port%s detected\n", hdev->maxchild,
|
dev_info (hub_dev, "%d port%s detected\n", hdev->maxchild,
|
||||||
(hdev->maxchild == 1) ? "" : "s");
|
(hdev->maxchild == 1) ? "" : "s");
|
||||||
|
|
||||||
|
hdev->children = kzalloc(hdev->maxchild *
|
||||||
|
sizeof(struct usb_device *), GFP_KERNEL);
|
||||||
hub->port_owners = kzalloc(hdev->maxchild * sizeof(void *), GFP_KERNEL);
|
hub->port_owners = kzalloc(hdev->maxchild * sizeof(void *), GFP_KERNEL);
|
||||||
if (!hub->port_owners) {
|
if (!hdev->children || !hub->port_owners) {
|
||||||
ret = -ENOMEM;
|
ret = -ENOMEM;
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
@ -1280,6 +1282,7 @@ static unsigned highspeed_hubs;
|
||||||
static void hub_disconnect(struct usb_interface *intf)
|
static void hub_disconnect(struct usb_interface *intf)
|
||||||
{
|
{
|
||||||
struct usb_hub *hub = usb_get_intfdata(intf);
|
struct usb_hub *hub = usb_get_intfdata(intf);
|
||||||
|
struct usb_device *hdev = interface_to_usbdev(intf);
|
||||||
|
|
||||||
/* Take the hub off the event list and don't let it be added again */
|
/* Take the hub off the event list and don't let it be added again */
|
||||||
spin_lock_irq(&hub_event_lock);
|
spin_lock_irq(&hub_event_lock);
|
||||||
|
@ -1301,6 +1304,7 @@ static void hub_disconnect(struct usb_interface *intf)
|
||||||
highspeed_hubs--;
|
highspeed_hubs--;
|
||||||
|
|
||||||
usb_free_urb(hub->urb);
|
usb_free_urb(hub->urb);
|
||||||
|
kfree(hdev->children);
|
||||||
kfree(hub->port_owners);
|
kfree(hub->port_owners);
|
||||||
kfree(hub->descriptor);
|
kfree(hub->descriptor);
|
||||||
kfree(hub->status);
|
kfree(hub->status);
|
||||||
|
@ -1676,7 +1680,7 @@ void usb_disconnect(struct usb_device **pdev)
|
||||||
usb_lock_device(udev);
|
usb_lock_device(udev);
|
||||||
|
|
||||||
/* Free up all the children before we remove this device */
|
/* Free up all the children before we remove this device */
|
||||||
for (i = 0; i < USB_MAXCHILDREN; i++) {
|
for (i = 0; i < udev->maxchild; i++) {
|
||||||
if (udev->children[i])
|
if (udev->children[i])
|
||||||
usb_disconnect(&udev->children[i]);
|
usb_disconnect(&udev->children[i]);
|
||||||
}
|
}
|
||||||
|
|
|
@ -501,7 +501,7 @@ struct usb_device {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int maxchild;
|
int maxchild;
|
||||||
struct usb_device *children[USB_MAXCHILDREN];
|
struct usb_device **children;
|
||||||
|
|
||||||
u32 quirks;
|
u32 quirks;
|
||||||
atomic_t urbnum;
|
atomic_t urbnum;
|
||||||
|
|
Loading…
Reference in New Issue