diff mbox series

dm: core: ofnode: safely fallback in ofnode_lookup_fdt

Message ID 20241113052050.1862420-1-caleb.connolly@linaro.org
State New
Headers show
Series dm: core: ofnode: safely fallback in ofnode_lookup_fdt | expand

Commit Message

Caleb Connolly Nov. 13, 2024, 5:20 a.m. UTC
Under some conditions it's possible to hit the null condition here like
when running with OF_LIVE and using the ofnode API before
initr_of_live() is called. There is very little null
checking for this in the FDT framework, so returning null here can
result in weird null pointer conditions.

Instead let's return the control FDT in the fallback case, this is
usually what the user was expecting.

Signed-off-by: Caleb Connolly <caleb.connolly@linaro.org>
---
 drivers/core/ofnode.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/drivers/core/ofnode.c b/drivers/core/ofnode.c
index 950895e72a99..7a7f25fc537c 100644
--- a/drivers/core/ofnode.c
+++ b/drivers/core/ofnode.c
@@ -152,9 +152,9 @@  void *ofnode_lookup_fdt(ofnode node)
 		uint i = OFTREE_TREE_ID(node.of_offset);
 
 		if (i >= oftree_count) {
 			log_debug("Invalid tree ID %x\n", i);
-			return NULL;
+			return (void *)gd->fdt_blob;
 		}
 
 		return oftree_list[i];
 	} else {