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>
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;
}
/**