summaryrefslogtreecommitdiff
path: root/common/usb.c
diff options
context:
space:
mode:
authorPaul Kocialkowski <contact@paulk.fr>2015-04-04 15:12:29 +0200
committerMarek Vasut <marex@denx.de>2015-04-14 05:47:48 +0200
commit04ee6ee2ca5ad419ebcbc64dae6e7128f32156fd (patch)
tree8abb7ed6f2cdbd5e7543a3ab4e1788710d90faa1 /common/usb.c
parent8879be88576024a48ae135ea0b3835727d8c9a3a (diff)
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>
Diffstat (limited to 'common/usb.c')
-rw-r--r--common/usb.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/common/usb.c b/common/usb.c
index 6ed31240fef..f6488475a7f 100644
--- a/common/usb.c
+++ b/common/usb.c
@@ -956,7 +956,7 @@ int usb_new_device(struct usb_device *dev)
*/
#ifndef CONFIG_USB_XHCI
err = usb_get_descriptor(dev, USB_DT_DEVICE, 0, desc, 64);
- if (err < 0) {
+ if (err < sizeof(struct usb_device_descriptor)) {
debug("usb_new_device: usb_get_descriptor() failed\n");
return -EIO;
}
@@ -996,6 +996,9 @@ int usb_new_device(struct usb_device *dev)
case 64:
dev->maxpacketsize = PACKET_SIZE_64;
break;
+ default:
+ printf("usb_new_device: invalid max packet size\n");
+ return -EIO;
}
dev->devnum = addr;