Commit 359439d2888fdc3797903963607bb0bbd4582e08
Committed by
Marek Vasut
1 parent
b6d7852cf8
Exists in
master
and in
54 other branches
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
common/usb.c
... | ... | @@ -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 |
common/usb_hub.c
... | ... | @@ -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 | } |