libpayload: usb: Fix several minor USB stack bugs
This patch fixes the following minor bugs in the USB stack:
1. Ensure that all dynamically allocated device structures are cleaned
on detachment, and that the device address is correctly released again.
2. Make sure MSC and HID drivers notice missing endpoints and actually
detach the device in that case (to prevent it from being used).
3. Make sure XHCI-specific set_address() cleans up all data structures
on failure.
4. Fix broken Slot ID range check that prevented XHCI devices from being
correctly cleaned up.
Change-Id: I7b2b9c8cd6c5e93cb19abcf01425bcd85d2e1f22
Signed-off-by: Julius Werner <jwerner@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/170665
Reviewed-by: Stefan Reinauer <reinauer@google.com>
Commit-Queue: Ronald Minnich <rminnich@chromium.org>
Tested-by: Ronald Minnich <rminnich@chromium.org>
(cherry picked from commit 9671472263ddd0c30400ae3b6da780a18cd21ded)
Signed-off-by: Isaac Christensen <isaac.christensen@se-eng.com>
Reviewed-on: http://review.coreboot.org/6701
Tested-by: build bot (Jenkins)
Reviewed-by: Paul Menzel <paulepanter@users.sourceforge.net>
Reviewed-by: Ronald G. Minnich <rminnich@gmail.com>
diff --git a/payloads/libpayload/drivers/usb/usbmsc.c b/payloads/libpayload/drivers/usb/usbmsc.c
index 037ead3..178f982 100644
--- a/payloads/libpayload/drivers/usb/usbmsc.c
+++ b/payloads/libpayload/drivers/usb/usbmsc.c
@@ -598,6 +598,7 @@
if (interface->bInterfaceProtocol != 0x50) {
usb_debug (" Protocol not supported.\n");
+ usb_detach_device (dev->controller, dev->address);
return;
}
@@ -606,6 +607,7 @@
(interface->bInterfaceSubClass != 6)) { // SCSI
/* Other protocols, such as ATAPI don't seem to be very popular. looks like ATAPI would be really easy to add, if necessary. */
usb_debug (" Interface SubClass not supported.\n");
+ usb_detach_device (dev->controller, dev->address);
return;
}
@@ -632,11 +634,13 @@
}
if (MSC_INST (dev)->bulk_in == 0) {
- usb_debug("couldn't find bulk-in endpoint");
+ usb_debug("couldn't find bulk-in endpoint.\n");
+ usb_detach_device (dev->controller, dev->address);
return;
}
if (MSC_INST (dev)->bulk_out == 0) {
- usb_debug("couldn't find bulk-out endpoint");
+ usb_debug("couldn't find bulk-out endpoint.\n");
+ usb_detach_device (dev->controller, dev->address);
return;
}
usb_debug (" using endpoint %x as in, %x as out\n",