mirror of
https://github.com/Fishwaldo/u-boot.git
synced 2025-03-19 13:41:31 +00:00
dm: usb: Avoid exceeding available array size for storage devices
The limit on storage devices is USB_MAX_STOR_DEV but we use one extra element while probing to see if a device is a storage device. Avoid this, since it causes memory corruption. Signed-off-by: Simon Glass <sjg@chromium.org> Reviewed-by: Marek Vasut <marex@denx.de> Tested-by: Stephen Warren <swarren@nvidia.com>
This commit is contained in:
parent
2a981dc2c6
commit
c89e79d419
1 changed files with 7 additions and 7 deletions
|
@ -176,6 +176,13 @@ static int usb_stor_probe_device(struct usb_device *dev)
|
||||||
if (dev == NULL)
|
if (dev == NULL)
|
||||||
return -ENOENT; /* no more devices available */
|
return -ENOENT; /* no more devices available */
|
||||||
|
|
||||||
|
/* We don't have space to even probe if we hit the maximum */
|
||||||
|
if (usb_max_devs == USB_MAX_STOR_DEV) {
|
||||||
|
printf("max USB Storage Device reached: %d stopping\n",
|
||||||
|
usb_max_devs);
|
||||||
|
return -ENOSPC;
|
||||||
|
}
|
||||||
|
|
||||||
debug("\n\nProbing for storage\n");
|
debug("\n\nProbing for storage\n");
|
||||||
if (usb_storage_probe(dev, 0, &usb_stor[usb_max_devs])) {
|
if (usb_storage_probe(dev, 0, &usb_stor[usb_max_devs])) {
|
||||||
/* OK, it's a storage device. Iterate over its LUNs
|
/* OK, it's a storage device. Iterate over its LUNs
|
||||||
|
@ -210,13 +217,6 @@ static int usb_stor_probe_device(struct usb_device *dev)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* if storage device */
|
|
||||||
if (usb_max_devs == USB_MAX_STOR_DEV) {
|
|
||||||
printf("max USB Storage Device reached: %d stopping\n",
|
|
||||||
usb_max_devs);
|
|
||||||
return -ENOSPC;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue