diff mbox

[U-Boot,v3,07/35] dm: Fix error handling when unflattening the DT

Message ID 20170612122202.3379-8-sjg@chromium.org
State Accepted
Delegated to: Simon Glass
Headers show

Commit Message

Simon Glass June 12, 2017, 12:21 p.m. UTC
The error handling code does not current detect an error right away.
Adjust it to return immediately.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

Changes in v3: None
Changes in v2: None

 lib/of_live.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

Comments

Simon Glass July 6, 2017, 5:36 p.m. UTC | #1
The error handling code does not current detect an error right away.
Adjust it to return immediately.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

Changes in v3: None
Changes in v2: None

 lib/of_live.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

Applied to u-boot-dm, thanks!
diff mbox

Patch

diff --git a/lib/of_live.c b/lib/of_live.c
index 51927f9e91..f351483387 100644
--- a/lib/of_live.c
+++ b/lib/of_live.c
@@ -216,9 +216,12 @@  static void *unflatten_dt_node(const void *blob, void *mem, int *poffset,
 	*poffset = fdt_next_node(blob, *poffset, &depth);
 	if (depth < 0)
 		depth = 0;
-	while (*poffset > 0 && depth > old_depth)
+	while (*poffset > 0 && depth > old_depth) {
 		mem = unflatten_dt_node(blob, mem, poffset, np, NULL,
 					fpsize, dryrun);
+		if (!mem)
+			return NULL;
+	}
 
 	if (*poffset < 0 && *poffset != -FDT_ERR_NOTFOUND) {
 		debug("unflatten: error %d processing FDT\n", *poffset);
@@ -286,6 +289,8 @@  static int unflatten_device_tree(const void *blob,
 	start = 0;
 	size = (unsigned long)unflatten_dt_node(blob, NULL, &start, NULL, NULL,
 						0, true);
+	if (!size)
+		return -EFAULT;
 	size = ALIGN(size, 4);
 
 	debug("  size is %lx, allocating...\n", size);