From patchwork Tue Mar 28 00:45:11 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andre Przywara X-Patchwork-Id: 744033 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 3vsXP515Z5z9s7D for ; Tue, 28 Mar 2017 11:50:17 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id 87DDCC21C33; Tue, 28 Mar 2017 00:48:33 +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 B79C0C21C3E; Tue, 28 Mar 2017 00:47:14 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id B1171C21C4A; Tue, 28 Mar 2017 00:46:46 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.101.70]) by lists.denx.de (Postfix) with ESMTP id 45E11C21C35 for ; Tue, 28 Mar 2017 00:46:42 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id A286028; Mon, 27 Mar 2017 17:46:41 -0700 (PDT) Received: from slackpad.lan (usa-sjc-mx-foss1.foss.arm.com [217.140.101.70]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 9E8D83F220; Mon, 27 Mar 2017 17:46:38 -0700 (PDT) From: Andre Przywara To: Maxime Ripard , Jagan Teki , Simon Glass , Tom Rini Date: Tue, 28 Mar 2017 01:45:11 +0100 Message-Id: <1490661926-18400-4-git-send-email-andre.przywara@arm.com> X-Mailer: git-send-email 2.8.2 In-Reply-To: <1490661926-18400-1-git-send-email-andre.przywara@arm.com> References: <1490661926-18400-1-git-send-email-andre.przywara@arm.com> Cc: Philipp Tomsich , linux-sunxi@googlegroups.com, Michal Simek , u-boot@lists.denx.de, Icenowy Zheng Subject: [U-Boot] [PATCH v2 03/18] SPL: FIT: improve error handling 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: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" At the moment we ignore any errors due to missing FIT properties, instead go ahead and calculate our addresses with the -1 return value. Fix this and bail out if any of the mandatory properties are missing. Signed-off-by: Andre Przywara --- common/spl/spl_fit.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/common/spl/spl_fit.c b/common/spl/spl_fit.c index a4ac27b..55da37a 100644 --- a/common/spl/spl_fit.c +++ b/common/spl/spl_fit.c @@ -11,14 +11,17 @@ #include #include +#define FDT_ERROR ((ulong)(-1)) + static ulong fdt_getprop_u32(const void *fdt, int node, const char *prop) { const u32 *cell; int len; cell = fdt_getprop(fdt, node, prop, &len); - if (len != sizeof(*cell)) - return -1U; + if (!cell || len != sizeof(*cell)) + return FDT_ERROR; + return fdt32_to_cpu(*cell); } @@ -221,7 +224,11 @@ int spl_load_simple_fit(struct spl_image_info *spl_image, /* Get its information and set up the spl_image structure */ data_offset = fdt_getprop_u32(fit, node, "data-offset"); + if (data_offset == FDT_ERROR) + return -1; data_size = fdt_getprop_u32(fit, node, "data-size"); + if (data_size == FDT_ERROR) + return -1; load = fdt_getprop_u32(fit, node, "load"); debug("data_offset=%x, data_size=%x\n", data_offset, data_size); spl_image->load_addr = load; @@ -264,6 +271,10 @@ int spl_load_simple_fit(struct spl_image_info *spl_image, } fdt_offset = fdt_getprop_u32(fit, node, "data-offset"); fdt_len = fdt_getprop_u32(fit, node, "data-size"); + if (fdt_offset == FDT_ERROR || fdt_len == FDT_ERROR) { + debug("%s: cannot load FDT data\n" __func__); + return -1; + } /* * Read the device tree and place it after the image. There may be