U-Boot Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Xavier Drudis Ferran <xdrudis@tinet.cat>
To: u-boot@lists.denx.de
Cc: Simon Glass <sjg@chromium.org>, Lukasz Majewski <lukma@denx.de>,
	Sean Anderson <seanga2@gmail.com>, Marek Vasut <marex@denx.de>
Subject: [PATCH] cmd: usb: Prevent reset in usb tree/info  command
Date: Mon, 5 Jun 2023 17:20:41 +0200	[thread overview]
Message-ID: <ZH39SVA1vbZR3+Gk@xdrudis.tinet.cat> (raw)

Add a check to avoid dommed (by null pointer dereference) recursive
call, not only for UCLASS_BLK.

When booting my Rock Pi 4B+ with a USB mass storage stick plugged
into one of the USB 2 ports (EHCI), when it is plugged before power
on, when issuing a

usb tree

or

usb info

command I get a "Synchronous Error" and a reset just after printing the
mass storage device in the usb tree or usb info. It might depend on the
contents of the USB stick too, I'm not sure.

It seems like I have two devices as children of the mass storage
device.  When there's only a UCLASS_BLK it works fine, but when there's
a UCLASS_BLK and a UCLASS_BOOTDEV, it recurses with a null udev as
first parameter and fails.

Likewise for usb_show_info().

Not sure if this should be a patch, an RFC or a bug report.  There may
be a better way to solve this, I haven't researched commit
201417d700a2ab09 ("bootstd: Add the bootdev uclass") and bootdev flow
properly, or thought about cases where udev is not null but the
recursive call might need preventing too. Feel free to think it over
before merging (or after). But this at least fixes a reset at an
innocent looking usb tree or usb info command. Maybe we can improve it
later?

Cc: Simon Glass <sjg@chromium.org>
Cc: Lukasz Majewski <lukma@denx.de>
Cc: Marek Vasut <marex@denx.de>


Signed-off-by: Xavier Drudis Ferran <xdrudis@tinet.cat>
---
 cmd/usb.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/cmd/usb.c b/cmd/usb.c
index 73addb04c4..7e6065aa51 100644
--- a/cmd/usb.c
+++ b/cmd/usb.c
@@ -421,7 +421,8 @@ static void usb_show_tree_graph(struct usb_device *dev, char *pre)
 		 * Ignore emulators and block child devices, we only want
 		 * real devices
 		 */
-		if ((device_get_uclass_id(child) != UCLASS_USB_EMUL) &&
+		if (udev &&
+		    (device_get_uclass_id(child) != UCLASS_USB_EMUL) &&
 		    (device_get_uclass_id(child) != UCLASS_BLK)) {
 			usb_show_tree_graph(udev, pre);
 			pre[index] = 0;
@@ -607,7 +608,8 @@ static void usb_show_info(struct usb_device *udev)
 		    (device_get_uclass_id(child) != UCLASS_USB_EMUL) &&
 		    (device_get_uclass_id(child) != UCLASS_BLK)) {
 			udev = dev_get_parent_priv(child);
-			usb_show_info(udev);
+			if (udev)
+				usb_show_info(udev);
 		}
 	}
 }
-- 
2.20.1



             reply	other threads:[~2023-06-05 15:20 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-05 15:20 Xavier Drudis Ferran [this message]
2023-06-07 22:05 ` [PATCH] cmd: usb: Prevent reset in usb tree/info command Marek Vasut
2023-06-08  7:39   ` Xavier Drudis Ferran
2023-06-09  1:20     ` Marek Vasut
     [not found]       ` <ZILsTOaXliizQjiH@xdrudis.tinet.cat>
2023-06-09 18:52         ` [SPAM] " Xavier Drudis Ferran
2023-06-11 12:29           ` Marek Vasut
2023-06-12 21:17             ` Simon Glass
2023-06-13  6:42               ` Xavier Drudis Ferran
2023-06-13  6:52             ` Xavier Drudis Ferran
2023-06-13 14:58               ` Simon Glass
2023-06-13 16:04                 ` Xavier Drudis Ferran
2023-06-13 20:12                   ` Simon Glass
2023-06-14  8:40                     ` Xavier Drudis Ferran
2023-06-20 10:03                       ` Simon Glass
2023-06-20 11:20                         ` Xavier Drudis Ferran
2023-06-20 14:36                           ` Simon Glass
2023-06-20  0:50               ` Marek Vasut
2023-06-20  7:03                 ` Xavier Drudis Ferran
2023-06-20  9:13                   ` Marek Vasut
  -- strict thread matches above, loose matches on Subject: below --
2023-06-19 10:26 Xavier Drudis Ferran
2023-06-19 11:54 ` Marek Vasut
     [not found] <ZJAqKxrO7qa8r6Kq@xdrudis.tinet.cat>
2023-06-19 21:49 ` Marek Vasut
2023-06-20  9:17   ` Xavier Drudis Ferran
2023-06-20  9:49     ` Marek Vasut

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZH39SVA1vbZR3+Gk@xdrudis.tinet.cat \
    --to=xdrudis@tinet.cat \
    --cc=lukma@denx.de \
    --cc=marex@denx.de \
    --cc=seanga2@gmail.com \
    --cc=sjg@chromium.org \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox