[PATCH 02/10] nvmem: core: validate DT cell bits before allocating the name
From: srini
Date: Tue Dec 01 2026 - 18:27:27 EST
From: James Hilliard <james.hilliard1@xxxxxxxxx>
An invalid bits property makes nvmem_add_cells_from_dt() return before
it frees the cell name. Allocate the name after validating the property,
and fail before invoking the provider fixup if allocation fails.
Fixes: def3173d4f17 ("nvmem: core: Print error on wrong bits DT property")
Cc: stable@xxxxxxxxxxxxxxx
Link: https://lore.kernel.org/r/sashiko-outbox-219531@xxxxxxxxxx/
Signed-off-by: James Hilliard <james.hilliard1@xxxxxxxxx>
Signed-off-by: Srinivas Kandagatla <srini@xxxxxxxxxx>
---
drivers/nvmem/core.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
index d976c0d6603b..c54d57e4bb4a 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -818,7 +818,6 @@ int nvmem_add_cells_from_dt(struct nvmem_device *nvmem, struct device_node *np)
info.offset = be32_to_cpup(addr++);
info.bytes = be32_to_cpup(addr);
- info.name = kasprintf(GFP_KERNEL, "%pOFn", child);
addr = of_get_property(child, "bits", &len);
if (addr && len == (2 * sizeof(u32))) {
@@ -832,6 +831,9 @@ int nvmem_add_cells_from_dt(struct nvmem_device *nvmem, struct device_node *np)
}
}
+ info.name = kasprintf(GFP_KERNEL, "%pOFn", child);
+ if (!info.name)
+ return -ENOMEM;
info.np = of_node_get(child);
if (nvmem->fixup_dt_cell_info)
--
2.53.0