[U-Boot] [PATCH v2] cmd: usb: add check on usb_stor_curr_dev in usb dev command

Patrick Delaunay patrick.delaunay at st.com
Tue Sep 12 08:57:56 UTC 2017


If the command 'usb start' is successfully executed but
U-Boot don't found a storage device (usb_stor_curr_dev stay to -1)
the next command 'usb dev' without parameter
leads to data abort after the message "USB device -1"

The added check on usb_stor_curr_dev avoid the issue.

Signed-off-by: Patrick Delaunay <patrick.delaunay at st.com>
---

Changes in v2:
- Updated the commit message
- use command_ret_t for result

 cmd/usb.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/cmd/usb.c b/cmd/usb.c
index 992d414..53305bb 100644
--- a/cmd/usb.c
+++ b/cmd/usb.c
@@ -806,6 +806,10 @@ static int do_usb(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 			printf("... is now current device\n");
 			return 0;
 		} else {
+			if (usb_stor_curr_dev < 0) {
+				printf("no current device selected\n");
+				return CMD_RET_FAILURE;
+			}
 			printf("\nUSB device %d: ", usb_stor_curr_dev);
 			stor_dev = blk_get_devnum_by_type(IF_TYPE_USB,
 							  usb_stor_curr_dev);
-- 
2.7.4



More information about the U-Boot mailing list