diff mbox series

[U-Boot,4/6] fdt: boot_get_fdt: unify 'fdt_len' validation (non-functional)

Message ID 20190331020838.26683-4-erosca@de.adit-jv.com
State Superseded
Delegated to: Simon Glass
Headers show
Series [U-Boot,1/6] fdt: boot_get_fdt: remove redundant zeroing out | expand

Commit Message

Eugeniu Rosca March 31, 2019, 2:08 a.m. UTC
Currently, there are two helpers called to determine the length of
FDT blobs embedded in the U-Boot-supported images:
 - image_multi_getimg(.., &fdt_len)
 - android_image_get_second(.., &fdt_len)

The returned 'fdt_len' value must match 'fdt_totalsize(fdt_blob)'.
Reduce the duplicated code by uniying the two checks.

No functional change is expected except that the error message
'fdt size != image size' will appear as a more generic
'fdt size mismatch!' to cover both use-cases.

Signed-off-by: Eugeniu Rosca <erosca@de.adit-jv.com>
---
 common/image-fdt.c | 18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)
diff mbox series

Patch

diff --git a/common/image-fdt.c b/common/image-fdt.c
index 68bcab85baf4..250f99aaaedd 100644
--- a/common/image-fdt.c
+++ b/common/image-fdt.c
@@ -270,6 +270,7 @@  int boot_get_fdt(int flag, int argc, char * const argv[], uint8_t arch,
 #endif
 	ulong		img_addr;
 	ulong		fdt_addr;
+	ulong		fdt_len = 0;
 	char		*fdt_blob = NULL;
 	void		*buf;
 #if CONFIG_IS_ENABLED(FIT)
@@ -428,7 +429,7 @@  int boot_get_fdt(int flag, int argc, char * const argv[], uint8_t arch,
 	} else if (images->legacy_hdr_valid &&
 			image_check_type(&images->legacy_hdr_os_copy,
 					 IH_TYPE_MULTI)) {
-		ulong fdt_data, fdt_len;
+		ulong fdt_data;
 
 		/*
 		 * Now check if we have a legacy multi-component image,
@@ -447,11 +448,6 @@  int boot_get_fdt(int flag, int argc, char * const argv[], uint8_t arch,
 				fdt_error("image is not a fdt");
 				goto error;
 			}
-
-			if (fdt_totalsize(fdt_blob) != fdt_len) {
-				fdt_error("fdt size != image size");
-				goto error;
-			}
 		} else {
 			debug("## No Flattened Device Tree\n");
 			goto no_fdt;
@@ -459,7 +455,7 @@  int boot_get_fdt(int flag, int argc, char * const argv[], uint8_t arch,
 #ifdef CONFIG_ANDROID_BOOT_IMAGE
 	} else if (genimg_get_format(buf) == IMAGE_FORMAT_ANDROID) {
 		struct andr_img_hdr *hdr = buf;
-		ulong fdt_data, fdt_len;
+		ulong fdt_data;
 
 		if (android_image_get_second(hdr, &fdt_data, &fdt_len) != 0)
 			goto no_fdt;
@@ -468,9 +464,6 @@  int boot_get_fdt(int flag, int argc, char * const argv[], uint8_t arch,
 		if (fdt_check_header(fdt_blob) != 0)
 			goto no_fdt;
 
-		if (fdt_totalsize(fdt_blob) != fdt_len)
-			goto error;
-
 		debug("## Using FDT found in Android image second area\n");
 #endif
 	} else {
@@ -478,6 +471,11 @@  int boot_get_fdt(int flag, int argc, char * const argv[], uint8_t arch,
 		goto no_fdt;
 	}
 
+	if (fdt_totalsize(fdt_blob) != fdt_len) {
+		fdt_error("fdt size mismatch!");
+		goto error;
+	}
+
 	*of_flat_tree = fdt_blob;
 	*of_size = fdt_totalsize(fdt_blob);
 	debug("   of_flat_tree at 0x%08lx size 0x%08lx\n",