Commit af8eb7df authored by Oliver Neukum's avatar Oliver Neukum Committed by Greg Kroah-Hartman

[PATCH] USB: allocate memory for reset earlier

if we fail with -ENOMEM, we should do it before the device must be
reparsed.
parent 7e226ccb
...@@ -1198,12 +1198,18 @@ int usb_physical_reset_device(struct usb_device *dev) ...@@ -1198,12 +1198,18 @@ int usb_physical_reset_device(struct usb_device *dev)
if (port < 0) if (port < 0)
return -ENOENT; return -ENOENT;
descriptor = kmalloc(sizeof *descriptor, GFP_NOIO);
if (!descriptor) {
return -ENOMEM;
}
down(&usb_address0_sem); down(&usb_address0_sem);
/* Send a reset to the device */ /* Send a reset to the device */
if (usb_hub_port_reset(parent, port, dev, HUB_SHORT_RESET_TIME)) { if (usb_hub_port_reset(parent, port, dev, HUB_SHORT_RESET_TIME)) {
usb_hub_port_disable(parent, port); usb_hub_port_disable(parent, port);
up(&usb_address0_sem); up(&usb_address0_sem);
kfree(descriptor);
return(-ENODEV); return(-ENODEV);
} }
...@@ -1213,6 +1219,7 @@ int usb_physical_reset_device(struct usb_device *dev) ...@@ -1213,6 +1219,7 @@ int usb_physical_reset_device(struct usb_device *dev)
err("USB device not accepting new address (error=%d)", ret); err("USB device not accepting new address (error=%d)", ret);
usb_hub_port_disable(parent, port); usb_hub_port_disable(parent, port);
up(&usb_address0_sem); up(&usb_address0_sem);
kfree(descriptor);
return ret; return ret;
} }
...@@ -1230,10 +1237,7 @@ int usb_physical_reset_device(struct usb_device *dev) ...@@ -1230,10 +1237,7 @@ int usb_physical_reset_device(struct usb_device *dev)
* If nothing changed, we reprogram the configuration and then * If nothing changed, we reprogram the configuration and then
* the alternate settings. * the alternate settings.
*/ */
descriptor = kmalloc(sizeof *descriptor, GFP_NOIO);
if (!descriptor) {
return -ENOMEM;
}
ret = usb_get_descriptor(dev, USB_DT_DEVICE, 0, descriptor, ret = usb_get_descriptor(dev, USB_DT_DEVICE, 0, descriptor,
sizeof(*descriptor)); sizeof(*descriptor));
if (ret < 0) { if (ret < 0) {
...@@ -1260,7 +1264,7 @@ int usb_physical_reset_device(struct usb_device *dev) ...@@ -1260,7 +1264,7 @@ int usb_physical_reset_device(struct usb_device *dev)
"(expected %Zi, got %i)", "(expected %Zi, got %i)",
dev->devpath, dev->devpath,
sizeof(dev->descriptor), ret); sizeof(dev->descriptor), ret);
clear_bit(dev->devnum, dev->bus->devmap.devicemap); clear_bit(dev->devnum, dev->bus->devmap.devicemap);
dev->devnum = -1; dev->devnum = -1;
return -EIO; return -EIO;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment