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 261EEC0015E for ; Fri, 28 Jul 2023 12:40:49 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 1DA66868A5; Fri, 28 Jul 2023 14:40:47 +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="qdbWUMdW"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 075F38689A; Fri, 28 Jul 2023 14:40:23 +0200 (CEST) Received: from wfbtzhsv.outbound-mail.sendgrid.net (wfbtzhsv.outbound-mail.sendgrid.net [159.183.224.104]) (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 90E0A868E3 for ; Fri, 28 Jul 2023 14:40:18 +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=8yjo6ub2x0qkRcOOZk727zA7ZqgltOXng42tnCDMhAo=; b=qdbWUMdW+R3LsHiB4TeB16dMDmJSlGUa+Ng0eeb7VlVOPLT1rzbM9nP4BF6DLVEuT9qY QGNMsuCwziYwE4dzJzMeftkU32DgtENAyBzO9nu9CgRY/7P1uYcE6ZruUCkkGOxsz2UUat HYn8jhBIdlnV7BT4DwYOeZ4UhVy3TvBhmq2E9GV1sXChCQwTMFOCrHCyv/G9rtBfsP8YcM TO/MneFwviQEeWLH9NV0vUdb2YWgQsJkWaf+TZwXQ6Sztr2p361Uhe8nEp2ihIxaRpiQNr 3xF3O3Z5jigAM8ei/boRO20qULOtYspvtOhtdwVC62MPKCyJSspVCzjpSbwdEyuw== Received: by filterdrecv-65f68489c8-rwlcm with SMTP id filterdrecv-65f68489c8-rwlcm-1-64C3B730-3E 2023-07-28 12:40:16.779467069 +0000 UTC m=+6786258.538240155 Received: from bionic.localdomain (unknown) by geopod-ismtpd-3 (SG) with ESMTP id xld8k-tgTr6HyVdML__QYA Fri, 28 Jul 2023 12:40:16.499 +0000 (UTC) From: Jonas Karlman Subject: [PATCH v4 2/5] usb: dwc3-generic: Return early when there is no child node Date: Fri, 28 Jul 2023 12:40:17 +0000 (UTC) Message-ID: <20230728124011.1747408-3-jonas@kwiboo.se> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230728124011.1747408-1-jonas@kwiboo.se> References: <20230728124011.1747408-1-jonas@kwiboo.se> MIME-Version: 1.0 X-SG-EID: =?us-ascii?Q?TdbjyGynYnRZWhH+7lKUQJL+ZxmxpowvO2O9SQF5CwCVrYgcwUXgU5DKUU3QxA?= =?us-ascii?Q?fZekEeQsTe+RrMu3cja6a0h5PsjC5KJ5zVTuPCe?= =?us-ascii?Q?5p=2FqXnqs8vLjuTOpiyfVs0zmZtszQKzE6OKXrjf?= =?us-ascii?Q?NG1zJx7RbIDX5pEjmCNU4aIP+ia7kqZZz5u94RF?= =?us-ascii?Q?3VRExlbR8StaMTBkkp596u+oie0xNbAZHP2EAyC?= =?us-ascii?Q?ZintV4RFpm98vVlE=2FJEtSEFtmXHjMo0DA7HJvI?= To: Kever Yang , Simon Glass , Philipp Tomsich , Marek Vasut Cc: Akash Gajjar , Jagan Teki , FUKAUMI Naoki , Tianling Shen , 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 Reviewed-by: Marek Vasut Reviewed-by: Kever Yang --- v4: - Collect r-b tag v3: - Collect r-b tag 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