From patchwork Mon Jun 5 15:20:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xavier Drudis Ferran X-Patchwork-Id: 1790485 X-Patchwork-Delegate: marek.vasut@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QZckX5xQ7z20QH for ; Tue, 6 Jun 2023 01:20:52 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id EDA8D85BC7; Mon, 5 Jun 2023 17:20:47 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=tinet.cat Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by phobos.denx.de (Postfix, from userid 109) id 9639985B6E; Mon, 5 Jun 2023 17:20:46 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mx1.tinet.cat (mx1.dipta.cat [195.76.233.59]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 3689F846D5 for ; Mon, 5 Jun 2023 17:20:44 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=tinet.cat Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=xdrudis@tinet.cat X-ASG-Debug-ID: 1685978443-12aaf23c4d38060001-4l7tJC Received: from smtp01.tinet.cat (smtp01.tinet.org [195.77.216.131]) by mx1.tinet.cat with ESMTP id NMPXLI0VfsGALRhM; Mon, 05 Jun 2023 17:20:43 +0200 (CEST) X-Barracuda-Envelope-From: xdrudis@tinet.cat X-Barracuda-Effective-Source-IP: smtp01.tinet.org[195.77.216.131] X-Barracuda-Apparent-Source-IP: 195.77.216.131 Received: from xdrudis.tinet.cat (180.red-79-152-181.dynamicip.rima-tde.net [79.152.181.180]) by smtp01.tinet.cat (Postfix) with ESMTPSA id 1A67E605DE45; Mon, 5 Jun 2023 17:20:43 +0200 (CEST) Date: Mon, 5 Jun 2023 17:20:41 +0200 From: Xavier Drudis Ferran To: u-boot@lists.denx.de Cc: Simon Glass , Lukasz Majewski , Sean Anderson , Marek Vasut Subject: [PATCH] cmd: usb: Prevent reset in usb tree/info command Message-ID: X-ASG-Orig-Subj: [PATCH] cmd: usb: Prevent reset in usb tree/info command MIME-Version: 1.0 Content-Disposition: inline X-Barracuda-Connect: smtp01.tinet.org[195.77.216.131] X-Barracuda-Start-Time: 1685978443 X-Barracuda-URL: https://webmail.tinet.cat:443/cgi-mod/mark.cgi X-Barracuda-Scan-Msg-Size: 2349 X-Barracuda-BRTS-Status: 1 X-Barracuda-Bayes: INNOCENT GLOBAL 0.5030 1.0000 0.7500 X-Barracuda-Spam-Score: 0.75 X-Barracuda-Spam-Status: No, SCORE=0.75 using global scores of TAG_LEVEL=1000.0 QUARANTINE_LEVEL=6.0 KILL_LEVEL=8.0 tests= X-Barracuda-Spam-Report: Code version 3.2, rules version 3.2.3.109641 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------------------------- X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean 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 Cc: Lukasz Majewski Cc: Marek Vasut Signed-off-by: Xavier Drudis Ferran Reviewed-by: Simon Glass --- 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); } } }