From patchwork Mon Jul 12 07:40:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: chenguanqiao X-Patchwork-Id: 1503919 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=kuaishou.com header.i=@kuaishou.com header.a=rsa-sha256 header.s=dkim header.b=k8KFN3oM; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4GNhyG5n2cz9sRN for ; Mon, 12 Jul 2021 21:54:30 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 1292982D9B; Mon, 12 Jul 2021 13:54:28 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=kuaishou.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=kuaishou.com header.i=@kuaishou.com header.b="k8KFN3oM"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 63EB482C7A; Mon, 12 Jul 2021 09:40: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=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from bjfk-gateway01.kuaishou.com (smtpcn02.kuaishou.com [103.107.216.241]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 401AE82C7A for ; Mon, 12 Jul 2021 09:40:39 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=kuaishou.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=chenguanqiao@kuaishou.com Received: from bjm7-pm-mail22.kuaishou.com ([172.28.1.42]) by bjfk-gateway01.kuaishou.com with ESMTPS id 16C7eL9U092109 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 12 Jul 2021 15:40:21 +0800 (GMT-8) (envelope-from chenguanqiao@kuaishou.com) DKIM-Signature: v=1; a=rsa-sha256; d=kuaishou.com; s=dkim; c=relaxed/relaxed; t=1626075621; h=from:subject:to:date:message-id; bh=UTUx8cerBoeVNfmKMqRzDCTX5ODBLMijGkyzibf9038=; b=k8KFN3oM9ZG1sbg1kH/rWmTEU15kOMoylX/MNx/+0/d95Fgrqo4sFuH1SI3ayu5RLXE4wzxiPeQ 8txBCEI+38I80+8ZWLTRbzpJgnuIcIoxLqgnR2Bep9I/8H867vmGsdGSYqcqCAD703od5p9tL9NaO ADi3bxHkng6QH2k5YPU= Received: from localhost.localdomain (172.28.1.32) by bjm7-pm-mail22.kuaishou.com (172.28.1.42) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2176.2; Mon, 12 Jul 2021 15:40:21 +0800 From: chenguanqiao To: , CC: Chen Guanqiao Subject: [PATCH v3] dm: core: fix no null pointer detection in ofnode_get_addr_size_index() Date: Mon, 12 Jul 2021 15:40:20 +0800 Message-ID: <20210712074020.19214-1-chenguanqiao@kuaishou.com> X-Mailer: git-send-email 2.32.0 MIME-Version: 1.0 X-Originating-IP: [172.28.1.32] X-ClientProxiedBy: bjfk-pm-mail15.kuaishou.com (172.29.5.43) To bjm7-pm-mail22.kuaishou.com (172.28.1.42) X-DNSRBL: X-MAIL: bjfk-gateway01.kuaishou.com 16C7eL9U092109 X-Mailman-Approved-At: Mon, 12 Jul 2021 13:54:26 +0200 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 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.2 at phobos.denx.de X-Virus-Status: Clean From: Chen Guanqiao Fixed a defect of a null pointer being discovered by Coverity Scan: CID 331544: Null pointer dereferences (REVERSE_INULL) Null-checking "size" suggests that it may be null, but it has already been dereferenced on all paths leading to the check. Signed-off-by: Chen Guanqiao Reviewed-by: Simon Glass Reviewed-by: Simon Glass --- v3: Add this changelog. v2: 1. Remove redundant return. 2. apply patch to u-boot/next. drivers/core/ofnode.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/core/ofnode.c b/drivers/core/ofnode.c index eeeccfb446..dda6c76e83 100644 --- a/drivers/core/ofnode.c +++ b/drivers/core/ofnode.c @@ -329,7 +329,8 @@ static fdt_addr_t __ofnode_get_addr_size_index(ofnode node, int index, { int na, ns; - *size = FDT_SIZE_T_NONE; + if (size) + *size = FDT_SIZE_T_NONE; if (ofnode_is_np(node)) { const __be32 *prop_val; @@ -340,6 +341,7 @@ static fdt_addr_t __ofnode_get_addr_size_index(ofnode node, int index, &flags); if (!prop_val) return FDT_ADDR_T_NONE; + if (size) *size = size64; @@ -359,8 +361,6 @@ static fdt_addr_t __ofnode_get_addr_size_index(ofnode node, int index, index, na, ns, size, translate); } - - return FDT_ADDR_T_NONE; } fdt_addr_t ofnode_get_addr_size_index(ofnode node, int index, fdt_size_t *size)