Commit 04ee6ee2ca5ad419ebcbc64dae6e7128f32156fd
Committed by
Marek Vasut
1 parent
8879be8857
Exists in
v2017.01-smarct4x
and in
34 other branches
usb: Early failure when the first descriptor read fails or is invalid
This may happen when using an USB1 device on a controller that only supports USB2 (e.g. EHCI). Reading the first descriptor will fail (read 0 byte), so we can abort the process at this point instead of failing later and wasting time. Signed-off-by: Paul Kocialkowski <contact@paulk.fr>
Showing 1 changed file with 4 additions and 1 deletions Side-by-side Diff
common/usb.c
... | ... | @@ -956,7 +956,7 @@ |
956 | 956 | */ |
957 | 957 | #ifndef CONFIG_USB_XHCI |
958 | 958 | err = usb_get_descriptor(dev, USB_DT_DEVICE, 0, desc, 64); |
959 | - if (err < 0) { | |
959 | + if (err < sizeof(struct usb_device_descriptor)) { | |
960 | 960 | debug("usb_new_device: usb_get_descriptor() failed\n"); |
961 | 961 | return -EIO; |
962 | 962 | } |
... | ... | @@ -996,6 +996,9 @@ |
996 | 996 | case 64: |
997 | 997 | dev->maxpacketsize = PACKET_SIZE_64; |
998 | 998 | break; |
999 | + default: | |
1000 | + printf("usb_new_device: invalid max packet size\n"); | |
1001 | + return -EIO; | |
999 | 1002 | } |
1000 | 1003 | dev->devnum = addr; |
1001 | 1004 |