Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 884C7C001DF for ; Sat, 15 Jul 2023 23:10:43 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 42D6F84660; Sun, 16 Jul 2023 01:10:30 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=kwiboo.se Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=kwiboo.se header.i=@kwiboo.se header.b="mARBJIGT"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 39CA986213; Sun, 16 Jul 2023 01:10:29 +0200 (CEST) Received: from s.wrqvtzvf.outbound-mail.sendgrid.net (s.wrqvtzvf.outbound-mail.sendgrid.net [149.72.126.143]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 8721480628 for ; Sun, 16 Jul 2023 01:10:26 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=kwiboo.se Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=bounces+31435339-7456-u-boot=lists.denx.de@em2124.kwiboo.se DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kwiboo.se; h=from:subject:in-reply-to:references:mime-version:to:cc: content-transfer-encoding:content-type:cc:content-type:from:subject:to; s=s1; bh=jHLZk0/VYM9ARqUbAoGrS9NBFt4+O2fQrhY4UzzbPDg=; b=mARBJIGT3JTHR5JZ4Fy/OCrSND7WjgdJG4AopqZ6F7fllPODPJK27s076uf6QqwcYput gFi8sUNa6b5kE+v+0kFa93J/go2UH1bTtBZjEzhZGNJomxb6P02dxBQnbozoZRVIcB9A5K HjOoQtPv6FWPghRmDXWceBdeKcIW/6m7TD5Bun64R2dIqF7lMtl+Fl7tMu+39daYKr7W3i oIzNPEA5kzxVWg3rngV8b2P1zRK1bjdd7ZECZSGeU9ge5KftJLuid8FHwAxu+C+dEyjM6v 7gxaBheggi7eePhBZxG849/ZYJ//2RRcmrDfNo/NpX2a3FrjCyJKlRLC99i25L4g== Received: by filterdrecv-65f68489c8-74bx5 with SMTP id filterdrecv-65f68489c8-74bx5-1-64B32761-2 2023-07-15 23:10:25.095251724 +0000 UTC m=+5700857.962960188 Received: from bionic.localdomain (unknown) by geopod-ismtpd-9 (SG) with ESMTP id 616pFms8Q5SlzipejP2QTg Sat, 15 Jul 2023 23:10:24.885 +0000 (UTC) From: Jonas Karlman Subject: [PATCH v2 2/5] usb: dwc3-generic: Return early when there is no child node Date: Sat, 15 Jul 2023 23:10:25 +0000 (UTC) Message-ID: <20230715231020.1694772-3-jonas@kwiboo.se> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230715231020.1694772-1-jonas@kwiboo.se> References: <20230715231020.1694772-1-jonas@kwiboo.se> MIME-Version: 1.0 X-SG-EID: =?us-ascii?Q?TdbjyGynYnRZWhH+7lKUQJL+ZxmxpowvO2O9SQF5CwCVrYgcwUXgU5DKUU3QxA?= =?us-ascii?Q?fZekEeQsTe+RrMu3cja6a0h7+GAYNBg7hcycabo?= =?us-ascii?Q?bEmB7QW57lJrJoSMIZk3p9jOa8RAbXhHniSopu1?= =?us-ascii?Q?MFam6tP4MVnO3+bj2nBc25ysvRAfXW2VQKZVPU4?= =?us-ascii?Q?gW9jigyl8Yx+Y0GOHYQqoL7hTbl5Xpb6YwLn8sj?= =?us-ascii?Q?t5upEV+34W0=2FoIp6RNlc=2FqkPg7YoJbnAzaeFwD?= To: Kever Yang , Simon Glass , Philipp Tomsich , Marek Vasut Cc: Akash Gajjar , Jagan Teki , FUKAUMI Naoki , u-boot@lists.denx.de, Jonas Karlman X-Entity-ID: P7KYpSJvGCELWjBME/J5tg== Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=us-ascii 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 The current error check for device_find_first_child is not working as expected, the documentation for device_find_first_child mention: @devp: Returns first child device, or NULL if none Return: 0 Change to return early when there is no child node to avoid any possible null pointer dereference. Signed-off-by: Jonas Karlman --- v2: - Update commit message drivers/usb/dwc3/dwc3-generic.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/usb/dwc3/dwc3-generic.c b/drivers/usb/dwc3/dwc3-generic.c index 35e4b36a695e..4d5d500aefab 100644 --- a/drivers/usb/dwc3/dwc3-generic.c +++ b/drivers/usb/dwc3/dwc3-generic.c @@ -558,9 +558,9 @@ int dwc3_glue_probe(struct udevice *dev) return ret; } - ret = device_find_first_child(dev, &child); - if (ret) - return ret; + device_find_first_child(dev, &child); + if (!child) + return 0; if (glue->clks.count == 0) { ret = dwc3_glue_clk_init(child, glue); -- 2.41.0