Skip to contentSkip to conversation

cmd: usb: check if_type before using this device

PATCH New Peng Fan 3 participants 3 messages Jun 17, 2016

lore
Share & tools
lore

Peng Fan

author
#0 lore raw

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.

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
index b83d323..58d9db2 100644
@@ -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
Applied
#1 lore raw

PATCH 1/1 cmd: usb: check if_type before using this device

Quoted 6 lines · Peng Fan

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

Quoted 28 lines
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
index b83d323..58d9db2 100644
@@ -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
#2 lore raw

PATCH 1/1 cmd: usb: check if_type before using this device

In reply to Peng Fan
Quoted 16 lines · Peng Fan

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.

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(-)