diff options
| author | Romain Gantois <[email protected]> | 2026-02-17 10:27:52 +0100 |
|---|---|---|
| committer | Tom Rini <[email protected]> | 2026-03-03 10:34:45 -0600 |
| commit | 39e1ccc777563d8c769531f1dfce24d38d023086 (patch) | |
| tree | b5371dff5d8247029db6ec20bf24acb4ec047075 | |
| parent | 8d24789abed0822fbe41a2f9d72cf19650159dc6 (diff) | |
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 <[email protected]>
Signed-off-by: Romain Gantois <[email protected]>
Reviewed-by: Simon Glass <[email protected]>
| -rw-r--r-- | drivers/core/ofnode.c | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/drivers/core/ofnode.c b/drivers/core/ofnode.c index cf1cf8abfbe..3a36b6fdd03 100644 --- a/drivers/core/ofnode.c +++ b/drivers/core/ofnode.c @@ -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; } /** |
