Commit 359439d2888fdc3797903963607bb0bbd4582e08

Authored by Milind Choudhary
Committed by Marek Vasut
1 parent b6d7852cf8

usb: Clean up newly allocated device nodes in case of configuration failure

If probe of a newly connected device fails for some reason, clean up
the allocated entry in usb_dev array.

Signed-off-by: Milind Choudhary <milindc@codeaurora.org>
Signed-off-by: Simon Glass <sjg@chromium.org>

Showing 3 changed files with 15 additions and 0 deletions Side-by-side Diff

... ... @@ -805,6 +805,18 @@
805 805 return &usb_dev[dev_index - 1];
806 806 }
807 807  
  808 +/*
  809 + * Free the newly created device node.
  810 + * Called in error cases where configuring a newly attached
  811 + * device fails for some reason.
  812 + */
  813 +void usb_free_device(void)
  814 +{
  815 + dev_index--;
  816 + USB_PRINTF("Freeing device node: %d\n", dev_index);
  817 + memset(&usb_dev[dev_index], 0, sizeof(struct usb_device));
  818 + usb_dev[dev_index].devnum = -1;
  819 +}
808 820  
809 821 /*
810 822 * By the time we get here, the device has gotten a new device ID
... ... @@ -259,6 +259,8 @@
259 259 /* Run it through the hoops (find a driver, etc) */
260 260 if (usb_new_device(usb)) {
261 261 /* Woops, disable the port */
  262 + usb_free_device();
  263 + dev->children[port] = NULL;
262 264 USB_HUB_PRINTF("hub: disabling port %d\n", port + 1);
263 265 usb_clear_port_feature(dev, port + 1, USB_PORT_FEAT_ENABLE);
264 266 }
... ... @@ -392,6 +392,7 @@
392 392 struct usb_device *usb_alloc_new_device(void *controller);
393 393  
394 394 int usb_new_device(struct usb_device *dev);
  395 +void usb_free_device(void);
395 396  
396 397 #endif /*_USB_H_ */