diff mbox

[U-Boot,v4,03/20] SPL: FIT: improve error handling

Message ID 1493166772-24598-4-git-send-email-andre.przywara@arm.com
State Accepted
Commit 5c8c8faccf0e660040ada1a9376b74a6807d4f5f
Delegated to: Jagannadha Sutradharudu Teki
Headers show

Commit Message

Andre Przywara April 26, 2017, 12:32 a.m. UTC
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 <andre.przywara@arm.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
---
 common/spl/spl_fit.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

Comments

Heiko Stübner May 5, 2017, 3:39 p.m. UTC | #1
Am Mittwoch, 26. April 2017, 01:32:35 CEST schrieb Andre Przywara:
> 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 <andre.przywara@arm.com>
> Reviewed-by: Simon Glass <sjg@chromium.org>

On a rk3399-firefly
Tested-by: Heiko Stuebner <heiko@sntech.de>
Kever Yang May 16, 2017, 1:36 a.m. UTC | #2
On 04/26/2017 08:32 AM, Andre Przywara wrote:
> 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 <andre.przywara@arm.com>
> Reviewed-by: Simon Glass <sjg@chromium.org>

Reviewed-by: Kever Yang <kever.yang@rock-chips.com>
Tested-by: Kever Yang <kever.yang@rock-chips.com>

Thanks,
- Kever
> ---
>   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 85af980..ecd42d8 100644
> --- a/common/spl/spl_fit.c
> +++ b/common/spl/spl_fit.c
> @@ -11,14 +11,17 @@
>   #include <libfdt.h>
>   #include <spl.h>
>   
> +#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);
>   }
>   
> @@ -222,7 +225,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 -ENOENT;
>   	data_size = fdt_getprop_u32(fit, node, "data-size");
> +	if (data_size == FDT_ERROR)
> +		return -ENOENT;
>   	load = fdt_getprop_u32(fit, node, "load");
>   	debug("data_offset=%x, data_size=%x\n", data_offset, data_size);
>   	spl_image->load_addr = load;
> @@ -265,6 +272,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 -ENOENT;
> +	}
>   
>   	/*
>   	 * Read the device tree and place it after the image. There may be
diff mbox

Patch

diff --git a/common/spl/spl_fit.c b/common/spl/spl_fit.c
index 85af980..ecd42d8 100644
--- a/common/spl/spl_fit.c
+++ b/common/spl/spl_fit.c
@@ -11,14 +11,17 @@ 
 #include <libfdt.h>
 #include <spl.h>
 
+#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);
 }
 
@@ -222,7 +225,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 -ENOENT;
 	data_size = fdt_getprop_u32(fit, node, "data-size");
+	if (data_size == FDT_ERROR)
+		return -ENOENT;
 	load = fdt_getprop_u32(fit, node, "load");
 	debug("data_offset=%x, data_size=%x\n", data_offset, data_size);
 	spl_image->load_addr = load;
@@ -265,6 +272,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 -ENOENT;
+	}
 
 	/*
 	 * Read the device tree and place it after the image. There may be