[PATCH master 32/39] efi: payload: protect against missing state alias

Ahmad Fatoum a.fatoum at pengutronix.de
Mon Feb 16 00:44:32 PST 2026


of_find_node_by_alias() can return NULL if the "state" alias doesn't
exist. The NULL result was passed directly to state_new_from_node(),
causing a NULL pointer dereference.

Add a NULL check with a warning message.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 efi/payload/init.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/efi/payload/init.c b/efi/payload/init.c
index 03f831840de7..6d2bd046e4c2 100644
--- a/efi/payload/init.c
+++ b/efi/payload/init.c
@@ -306,7 +306,7 @@ static int efi_late_init(void)
 	free(fdt);
 
 	if (!IS_ERR(state_root)) {
-		struct device_node *np = NULL;
+		struct device_node *np;
 		struct state *state;
 
 		ret = barebox_register_of(state_root);
@@ -314,6 +314,10 @@ static int efi_late_init(void)
 			pr_warn("Failed to register device-tree: %pe\n", ERR_PTR(ret));
 
 		np = of_find_node_by_alias(state_root, "state");
+		if (!np) {
+			pr_warn("No state alias in %s\n", state_desc);
+			return 0;
+		}
 
 		state = state_new_from_node(np, false);
 		if (IS_ERR(state))
-- 
2.47.3




More information about the barebox mailing list