[PATCH] nvmem: layouts: u-boot-env: Put cell nodes on registration failure

From: Zhu Jun

Date: Wed Nov 11 2026 - 21:39:45 EST


u_boot_env_parse_cells() takes a reference to each matching child node
before registering its cell. nvmem_add_one_cell() transfers that reference
to the cell on success, but does not release it if cell allocation or
initialization fails.

Drop the node reference when registration fails, preserving the existing
behavior of continuing with the remaining environment variables.

OpenAI Codex assisted with analysis and patch preparation.

Fixes: 7c8979b42b1a ("nvmem: u-boot-env: use nvmem_add_one_cell() nvmem subsystem helper")
Signed-off-by: Zhu Jun <zhujun2@xxxxxxxxxxxxxxxxxxxx>
---
drivers/nvmem/layouts/u-boot-env.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/nvmem/layouts/u-boot-env.c b/drivers/nvmem/layouts/u-boot-env.c
index 33ec2350386f..f4839571b794 100644
--- a/drivers/nvmem/layouts/u-boot-env.c
+++ b/drivers/nvmem/layouts/u-boot-env.c
@@ -78,7 +78,8 @@ static int u_boot_env_parse_cells(struct device *dev, struct nvmem_device *nvmem
info.read_post_process = u_boot_env_read_post_process_ethaddr;
}

- nvmem_add_one_cell(nvmem, &info);
+ if (nvmem_add_one_cell(nvmem, &info))
+ of_node_put(info.np);
}

return 0;
--
2.51.0