]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
dm: core: Don't allow ofnode_to_fdt() to return NULL
authorRomain Gantois <romain.gantois@bootlin.com>
Tue, 17 Feb 2026 09:27:52 +0000 (10:27 +0100)
committerTom Rini <trini@konsulko.com>
Tue, 3 Mar 2026 16:34:45 +0000 (10:34 -0600)
The ofnode_to_fdt() function may return a NULL pointer in multiple cases.
Or, this function's return value is often passed directly to functions such
as fdt_getprop() which end up dereferencing it, thus causing a NULL pointer
exception.

Don't allow ofnode_to_fdt() to return NULL, to avoid a NULL pointer
dereference.

Reviewed-by: Raphaƫl Gallais-Pou <raphael.gallais-pou@foss.st.com>
Signed-off-by: Romain Gantois <romain.gantois@bootlin.com>
Reviewed-by: Simon Glass <simon.glass@canonical.com>
drivers/core/ofnode.c

index cf1cf8abfbe5ba146e1fdf8c28497f6de7a74d02..3a36b6fdd03137007fc292c6b6ac2609be2ddaa5 100644 (file)
@@ -164,15 +164,20 @@ void *ofnode_lookup_fdt(ofnode node)
 
 void *ofnode_to_fdt(ofnode node)
 {
+       void *fdt;
+
 #ifdef OF_CHECKS
        if (of_live_active())
-               return NULL;
+               panic("%s called with live tree in use!\n", __func__);
 #endif
        if (CONFIG_IS_ENABLED(OFNODE_MULTI_TREE) && ofnode_valid(node))
-               return ofnode_lookup_fdt(node);
+               fdt = ofnode_lookup_fdt(node);
+       else
+               fdt = (void *)gd->fdt_blob;
+
+       assert(fdt);
 
-       /* Use the control FDT by default */
-       return (void *)gd->fdt_blob;
+       return fdt;
 }
 
 /**