cmd: usb: check if_type before using this device
PATCH 1/1 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.
--- cmd/usb.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
cmd/usb.c +2 -1
@@ -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 ; }
Signature · 1 line
2.6.2
Marek Vasut
AppliedPATCH 1/1 cmd: usb: check if_type before using this device
Quoted 6 lines · Peng Fan
For legacy usb storage driver,
USB_MAX_STOR_DEVis defined as 7. If we only have one usb disk on board,usb dev 0is ok. But ifusb dev 1, still ok, thenusb read xxxwill trigger system fault and reboot.So check
if_typebefore using this device.
Applied, thanks
Quoted 28 lines
Signed-off-by Peng Fan <[email protected]>Cc Simon Glass <[email protected]>Cc Hans de Goede <[email protected]>Cc Bin Meng <[email protected]>Cc Marek Vasut <[email protected]>Cc Stefan Roese <[email protected]>Cc Marcel Ziswiler <[email protected]>Cc Peng Fan <[email protected]>Cc Stephen Warren <[email protected]>--- cmd/usb.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)cmd/usb.c +2
-1@@ -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 ; }
Signature · 2 lines
Best regards, Marek Vasut
PATCH 1/1 cmd: usb: check if_type before using this device
In reply to Peng FanQuoted 16 lines · Peng Fan
For legacy usb storage driver,
USB_MAX_STOR_DEVis defined as 7. If we only have one usb disk on board,usb dev 0is ok. But ifusb dev 1, still ok, thenusb read xxxwill trigger system fault and reboot.So check
if_typebefore using this device.Signed-off-by Peng Fan <[email protected]>Cc Simon Glass <[email protected]>Cc Hans de Goede <[email protected]>Cc Bin Meng <[email protected]>Cc Marek Vasut <[email protected]>Cc Stefan Roese <[email protected]>Cc Marcel Ziswiler <[email protected]>Cc Peng Fan <[email protected]>Cc Stephen Warren <[email protected]>
Quoted 3 lines
--- cmd/usb.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)