ChangeSet 1.1254.1.3, 2003/05/29 15:17:04-07:00, oliver@neukum.org [PATCH] USB: allocate memory for reset earlier if we fail with -ENOMEM, we should do it before the device must be reparsed. drivers/usb/core/hub.c | 14 +++++++++----- 1 files changed, 9 insertions(+), 5 deletions(-) diff -Nru a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c --- a/drivers/usb/core/hub.c Fri May 30 11:35:39 2003 +++ b/drivers/usb/core/hub.c Fri May 30 11:35:39 2003 @@ -1198,12 +1198,18 @@ if (port < 0) return -ENOENT; + descriptor = kmalloc(sizeof *descriptor, GFP_NOIO); + if (!descriptor) { + return -ENOMEM; + } + down(&usb_address0_sem); /* Send a reset to the device */ if (usb_hub_port_reset(parent, port, dev, HUB_SHORT_RESET_TIME)) { usb_hub_port_disable(parent, port); up(&usb_address0_sem); + kfree(descriptor); return(-ENODEV); } @@ -1213,6 +1219,7 @@ err("USB device not accepting new address (error=%d)", ret); usb_hub_port_disable(parent, port); up(&usb_address0_sem); + kfree(descriptor); return ret; } @@ -1230,10 +1237,7 @@ * If nothing changed, we reprogram the configuration and then * the alternate settings. */ - descriptor = kmalloc(sizeof *descriptor, GFP_NOIO); - if (!descriptor) { - return -ENOMEM; - } + ret = usb_get_descriptor(dev, USB_DT_DEVICE, 0, descriptor, sizeof(*descriptor)); if (ret < 0) { @@ -1260,7 +1264,7 @@ "(expected %Zi, got %i)", dev->devpath, sizeof(dev->descriptor), ret); - + clear_bit(dev->devnum, dev->bus->devmap.devicemap); dev->devnum = -1; return -EIO;