fdt: Check for a valid fdt in oftree_ensure()
Check the header before starting to use it, since this could provide
very confusing later, when ofnode calls start to fail.
Signed-off-by: Simon Glass <sjg@chromium.org>
diff --git a/drivers/core/ofnode.c b/drivers/core/ofnode.c
index f72ea41..21a233f 100644
--- a/drivers/core/ofnode.c
+++ b/drivers/core/ofnode.c
@@ -83,6 +83,11 @@
if (check_tree_count())
return oftree_null();
+ if (fdt_check_header(fdt)) {
+ log_err("Invalid device tree blob header\n");
+ return oftree_null();
+ }
+
/* register the new tree */
i = oftree_count++;
oftree_list[i] = fdt;