summaryrefslogtreecommitdiff
path: root/common/usb.c
diff options
context:
space:
mode:
authorMilind Choudhary <milindc@codeaurora.org>2010-10-13 10:42:57 -0700
committerSimon Glass <sjg@chromium.org>2011-08-24 09:56:47 -0700
commitfd6f22036e3bd47e2a6438215ea0b39df3ddf772 (patch)
treec9293da0d6dd2b1fba8371097459fe7f9b3e65db /common/usb.c
parent728f95f4413186cf0bbafefb45bb495da32d289a (diff)
Cleanup 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. Change-Id: I90fc5dde3bffb95cee19da2423fe3ff9ac546214 Signed-off-by: Milind Choudhary <milindc@codeaurora.org> Review URL: http://codereview.chromium.org/3054035 Patch from Milind Choudhary <milindc@codeaurora.org>.
Diffstat (limited to 'common/usb.c')
-rw-r--r--common/usb.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/common/usb.c b/common/usb.c
index 8afe5875774..f924c5a1290 100644
--- a/common/usb.c
+++ b/common/usb.c
@@ -765,6 +765,18 @@ struct usb_device *usb_alloc_new_device(void)
return &usb_dev[dev_index - 1];
}
+/*
+ * Free the newly created device node.
+ * Called in error cases where configuring a newly attached
+ * device fails for some reason.
+ */
+void usb_free_device(void)
+{
+ dev_index--;
+ USB_PRINTF("Freeing device node: %d \n", dev_index);
+ memset(&usb_dev[dev_index], 0, sizeof(struct usb_device));
+ usb_dev[dev_index].devnum = -1;
+}
/*
* By the time we get here, the device has gotten a new device ID
@@ -1250,6 +1262,8 @@ void usb_hub_port_connect_change(struct usb_device *dev, int port)
/* Run it through the hoops (find a driver, etc) */
if (usb_new_device(usb)) {
/* Woops, disable the port */
+ usb_free_device();
+ dev->children[port] = NULL;
USB_HUB_PRINTF("hub: disabling port %d\n", port + 1);
usb_clear_port_feature(dev, port + 1, USB_PORT_FEAT_ENABLE);
}