Commit 7839f5f8092762f048076c6c7b010c10f2ee8a0b

Authored by Peng Fan
Committed by Marek Vasut
1 parent ef53b8c4ce

cmd: usb: check if_type before using this device

For legacy usb storage driver, USB_MAX_STOR_DEV is defined as 7.
If we only have one usb disk on board, `usb dev 0` is ok.
But if `usb dev 1`, still ok, then `usb read xxx` will trigger
system fault and reboot.

So check if_type before using this device.

Signed-off-by: Peng Fan <peng.fan@nxp.com>
Cc: Simon Glass <sjg@chromium.org>
Cc: Hans de Goede <hdegoede@redhat.com>
Cc: Bin Meng <bmeng.cn@gmail.com>
Cc: Marek Vasut <marex@denx.de>
Cc: Stefan Roese <sr@denx.de>
Cc: Marcel Ziswiler <marcel.ziswiler@toradex.com>
Cc: Peng Fan <peng.fan@nxp.com>
Cc: Stephen Warren <swarren@nvidia.com>

Showing 1 changed file with 2 additions and 1 deletions Side-by-side Diff

... ... @@ -800,7 +800,8 @@
800 800 int dev = (int)simple_strtoul(argv[2], NULL, 10);
801 801 printf("\nUSB device %d: ", dev);
802 802 stor_dev = blk_get_devnum_by_type(IF_TYPE_USB, dev);
803   - if (stor_dev == NULL) {
  803 + if ((stor_dev == NULL) ||
  804 + (stor_dev->if_type == IF_TYPE_UNKNOWN)) {
804 805 printf("unknown device\n");
805 806 return 1;
806 807 }