diff mbox series

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

Message ID 1505206676-13222-1-git-send-email-patrick.delaunay@st.com
State Rejected
Headers show
Series [U-Boot,v2] cmd: usb: add check on usb_stor_curr_dev in usb dev command | expand

Commit Message

Patrick DELAUNAY Sept. 12, 2017, 8:57 a.m. UTC
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@st.com>
---

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

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

Comments

Patrick DELAUNAY Sept. 12, 2017, 9:32 a.m. UTC | #1
Hi Marek,

> Subject: [PATCH v2] cmd: usb: add check on usb_stor_curr_dev in usb dev command
> 
> 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@st.com>
> ---
> 
> Changes in v2:
> - Updated the commit message
> - use command_ret_t for result

After push V2 version today, I try to rebase my patch on latest version on v2017.09
But I have conflict with the patch wich introduce blk_common_cmd() usage.

So I check that the issue is still present with the same test on sandbox....
before to found a way to solve the merge conflict,
And in fact the issue is now solved without patch.

He confirmes it with code review for the 2 case in  blk_print_device_num()
=> Loop in get_desc() for blk-uclass.c (-1 is no more used as index)
=> check devnum < 0 in get_desc() for blk_legacy.c

So I will abandon my patch....

Test done on sandbox :

Remove flash-stick for node usb@1  in arch/sandbox/dts/sandbox.dts

$> make sandbox_defconfig
$> make
$> ./u-boot -d u-boot.dtb


U-Boot 2017.09-00001-gdbdb82c (Sep 12 2017 - 10:59:47 +0200)

Model: sandbox
DRAM:  128 MiB
MMC:   
Using default environment

In:    cros-ec-keyb
Out:   vidconsole
Err:   vidconsole
Model: sandbox
SCSI:  Net:   eth0: eth@10002000, eth1: eth@80000000, eth5: eth@90000000
IDE:   Bus 0: not available  
=> usb start
starting USB...
USB0:   scanning bus 0 for devices... 1 USB Device(s) found
       scanning usb for storage devices... 0 Storage Device(s) found
=> usb dev

no usb devices available
=>

Best Regards, Patrick
diff mbox series

Patch

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