dm: core: Don't allow ofnode_to_fdt() to return NULL

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>
This commit is contained in:
Romain Gantois
2026-03-03 10:34:45 -06:00
committed by Tom Rini
parent 8d24789abe
commit 39e1ccc777
+9 -4
View 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;
/* Use the control FDT by default */
return (void *)gd->fdt_blob;
assert(fdt);
return fdt;
}
/**