From mboxrd@z Thu Jan 1 00:00:00 1970 From: Marek Vasut Date: Sat, 18 Jun 2016 00:48:40 +0200 Subject: [U-Boot] [PATCH] cmd: usb: check if_type before using this device In-Reply-To: <1466144291-32522-1-git-send-email-peng.fan@nxp.com> References: <1466144291-32522-1-git-send-email-peng.fan@nxp.com> Message-ID: <57647E48.3090106@denx.de> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de On 06/17/2016 08:18 AM, Peng Fan wrote: > 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. Applied, thanks > Signed-off-by: Peng Fan > Cc: Simon Glass > Cc: Hans de Goede > Cc: Bin Meng > Cc: Marek Vasut > Cc: Stefan Roese > Cc: Marcel Ziswiler > Cc: Peng Fan > Cc: Stephen Warren > --- > cmd/usb.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/cmd/usb.c b/cmd/usb.c > index b83d323..58d9db2 100644 > --- a/cmd/usb.c > +++ b/cmd/usb.c > @@ -800,7 +800,8 @@ static int do_usb(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) > int dev = (int)simple_strtoul(argv[2], NULL, 10); > printf("\nUSB device %d: ", dev); > stor_dev = blk_get_devnum_by_type(IF_TYPE_USB, dev); > - if (stor_dev == NULL) { > + if ((stor_dev == NULL) || > + (stor_dev->if_type == IF_TYPE_UNKNOWN)) { > printf("unknown device\n"); > return 1; > } > -- Best regards, Marek Vasut