[PATCH] USB: Fix resource leakage in the hub driver
The hub driver is very careless about returning resources when an error occurs while installing a new device. This patch attempts to put some order back into the situation. Details: Since usb_new_device() allocates neither the device structure nor the device address, it shouldn't release either one. Because usb_new_device() no longer releases the device structure, usb_register_root_hub() doesn't need to take an extra reference to it. Since the device address selection and TT setup code is used only for new devices, not ones being reset, move that code from hub_port_init() to hub_port_connect_change(). By the same token, hub_port_init() doesn't have to release the device address or the device structure. Just to make things look better, move the failure code in hub_port_init() to the end of the routine. And when disabling endpoint 0, disable both the IN and OUT parts of the endpoint. In hub_port_connect_change(), make all the failure paths execute the same code so that resources are always released. These resources comprise: the pointer from the parent to the new child device, the HCD state for ep0, the device's address, and the device structure itself -- in short, everything that's set up before calling usb_new_device(). Signed-off-by: Alan Stern <stern@rowland.harvard.edu> Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Showing
Please register or sign in to comment