diff mbox series

[2/5] nvmem: core: read OF defined NVMEM cell name from "label" property

Message ID 20211223110755.22722-3-zajec5@gmail.com (mailing list archive)
State Not Applicable
Headers show
Series nvmem: support more NVMEM cells variants | expand

Checks

Context Check Description
netdev/tree_selection success Not a local patch

Commit Message

Rafał Miłecki Dec. 23, 2021, 11:07 a.m. UTC
From: Rafał Miłecki <rafal@milecki.pl>

Prefer it over $nodename. Property "label" allows more fancy /
customized names with special characters.

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
---
 drivers/nvmem/core.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
index 23a38dcf0fc4..45c39ac401bd 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -685,6 +685,7 @@  static int nvmem_add_cells_from_of(struct nvmem_device *nvmem)
 	struct device *dev = &nvmem->dev;
 	struct nvmem_cell_entry *cell;
 	const __be32 *addr;
+	const char *label;
 	int len;
 
 	parent = dev->of_node;
@@ -708,7 +709,11 @@  static int nvmem_add_cells_from_of(struct nvmem_device *nvmem)
 		cell->nvmem = nvmem;
 		cell->offset = be32_to_cpup(addr++);
 		cell->bytes = be32_to_cpup(addr);
-		cell->name = kasprintf(GFP_KERNEL, "%pOFn", child);
+
+		if (!of_property_read_string(child, "label", &label))
+			cell->name = kasprintf(GFP_KERNEL, "%s", label);
+		else
+			cell->name = kasprintf(GFP_KERNEL, "%pOFn", child);
 
 		addr = of_get_property(child, "bits", &len);
 		if (addr && len == (2 * sizeof(u32))) {