diff --git a/drivers/usb/core/config.c b/drivers/usb/core/config.c index 417140b012bb..67475ff81641 100644 --- a/drivers/usb/core/config.c +++ b/drivers/usb/core/config.c @@ -944,11 +944,11 @@ int usb_get_configuration(struct usb_device *dev) length = ncfg * sizeof(char *); dev->rawdescriptors = kzalloc(length, GFP_KERNEL); if (!dev->rawdescriptors) - return -ENOMEM; + goto bailout2; desc = kmalloc(USB_DT_CONFIG_SIZE, GFP_KERNEL); if (!desc) - return -ENOMEM; + goto bailout; for (cfgno = 0; cfgno < ncfg; cfgno++) { /* We grab just the first descriptor so we know how long @@ -1012,6 +1012,15 @@ int usb_get_configuration(struct usb_device *dev) dev->descriptor.bNumConfigurations = cfgno; return result; + +bailout: + kfree(dev->rawdescriptors); + dev->rawdescriptors = NULL; +bailout2: + kfree(dev->config); + dev->config = NULL; + + return -ENOMEM; } void usb_release_bos_descriptor(struct usb_device *dev)