From patchwork Tue Oct 8 00:22:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiko Stuebner X-Patchwork-Id: 1173029 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=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=sntech.de Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 46nJ2j57vKz9s4Y for ; Tue, 8 Oct 2019 11:22:37 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id 45D90C21F67; Tue, 8 Oct 2019 00:22:16 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 124C2C21EE7; Tue, 8 Oct 2019 00:22:15 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id E28E2C21F04; Tue, 8 Oct 2019 00:22:13 +0000 (UTC) Received: from gloria.sntech.de (gloria.sntech.de [185.11.138.130]) by lists.denx.de (Postfix) with ESMTPS id 8ECB6C21D65 for ; Tue, 8 Oct 2019 00:22:13 +0000 (UTC) Received: from ip5f5a6266.dynamic.kabel-deutschland.de ([95.90.98.102] helo=phil.fritz.box) by gloria.sntech.de with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.89) (envelope-from ) id 1iHdGV-0006GU-Bc; Tue, 08 Oct 2019 02:22:11 +0200 From: Heiko Stuebner To: u-boot@lists.denx.de Date: Tue, 8 Oct 2019 02:22:05 +0200 Message-Id: <20191008002207.14396-1-heiko@sntech.de> X-Mailer: git-send-email 2.23.0 MIME-Version: 1.0 Cc: andre.przywara@arm.com, robin.murphy@arm.com, christoph.muellner@theobroma-systems.com Subject: [U-Boot] [PATCH 1/3] fdtdec: protect against another NULL phandlep in fdtdec_add_reserved_memory() X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 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" The change adding fdtdec_add_reserved_memory() already protected the added phandle against the phandlep being NULL - making the phandlep var optional. But in the early code checking for an already existing carveout this check was not done and thus the phandle assignment could run into trouble, so add a check there as well, which makes the function still return sucessfully if a matching region is found, even though no-one wants to work with the phandle. Fixes: c9222a08b3f7 ("fdtdec: Implement fdtdec_add_reserved_memory()") Signed-off-by: Heiko Stuebner --- lib/fdtdec.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/fdtdec.c b/lib/fdtdec.c index 74525c84e7..17455c5506 100644 --- a/lib/fdtdec.c +++ b/lib/fdtdec.c @@ -1363,7 +1363,8 @@ int fdtdec_add_reserved_memory(void *blob, const char *basename, } if (addr == carveout->start && (addr + size) == carveout->end) { - *phandlep = fdt_get_phandle(blob, node); + if (phandlep) + *phandlep = fdt_get_phandle(blob, node); return 0; } }