Skip to contentSkip to conversation

nvmem: core: append offset to cell name in sysfs

PATCH In review Daniel Golle 3 participants 4 messages Jul 18, 2023 – Jul 31, 2023 NVMEM framework

lore
Share & tools
lore
#0 lore raw

PATCH 2/2 nvmem: core: append offset to cell name in sysfs

The device tree node names are not required to be unique. Append the offset to the name to make cell nodes with identical names become accessible via sysfs and avoid kernel stackdump caused by
sysfs: cannot create duplicate filename '...'

Fixes 757f8b3835c9 ("nvmem: core: Expose cells through sysfs")
---
 drivers/nvmem/core.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/nvmem/core.c +3 -1
index 70e951088826d..90fe9dc30f8ba 100644
@@ -480,7 +480,9 @@ static int nvmem_populate_sysfs_cells(struct nvmem_device *nvmem)
 	/* Initialize each attribute to take the name and size of the cell */
 	list_for_each_entry(entry, &nvmem->cells, node) {
 		sysfs_bin_attr_init(&attrs[i]);
-		attrs[i].attr.name = devm_kstrdup(&nvmem->dev, entry->name, GFP_KERNEL);
+		attrs[i].attr.name = devm_kasprintf(&nvmem->dev, GFP_KERNEL,
+						    "%s@%d", entry->name,
+						    entry->offset);
 		attrs[i].attr.mode = 0444;
 		attrs[i].size = entry->bytes;
 		attrs[i].read = &nvmem_cell_attr_read;
Signature · 1 line
2.41.0
#1 lore raw
Quoted 16 lines · Daniel Golle

The device tree node names are not required to be unique. Append the offset to the name to make cell nodes with identical names become accessible via sysfs and avoid kernel stackdump caused by
sysfs: cannot create duplicate filename '...'

Fixes 757f8b3835c9 ("nvmem: core: Expose cells through sysfs")
---
 drivers/nvmem/core.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/nvmem/core.c +0 -0
index 70e951088826d..90fe9dc30f8ba 100644

drivers/nvmem/core.c static int nvmem_populate_sysfs_cells(struct nvmem_device *nvmem) · line 485

Quoted 7 lines
drivers/nvmem/core.c +3 -1
@@ -480,7 +480,9 @@ static int nvmem_populate_sysfs_cells(struct nvmem_device *nvmem)
 	/* Initialize each attribute to take the name and size of the cell */
 	list_for_each_entry(entry, &nvmem->cells, node) {
 		sysfs_bin_attr_init(&attrs[i]);
-		attrs[i].attr.name = devm_kstrdup(&nvmem->dev, entry->name, GFP_KERNEL);
+		attrs[i].attr.name = devm_kasprintf(&nvmem->dev, GFP_KERNEL,
+						    "%s@%d", entry->name,
+						    entry->offset);

No documenatation update to show the new naming scheme?

And again, I don't see that git id in Linus's tree, am I just not up to date properly?

thanks,

greg k-h

#2 lore raw
In reply to Daniel Golle

Hi Daniel,

[email protected] wrote on Tue, 18 Jul 2023 14:55:57 +0100:

Quoted 16 lines

The device tree node names are not required to be unique. Append the offset to the name to make cell nodes with identical names become accessible via sysfs and avoid kernel stackdump caused by
sysfs: cannot create duplicate filename '...'

Fixes 757f8b3835c9 ("nvmem: core: Expose cells through sysfs")
---
 drivers/nvmem/core.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/nvmem/core.c +0 -0
index 70e951088826d..90fe9dc30f8ba 100644

drivers/nvmem/core.c static int nvmem_populate_sysfs_cells(struct nvmem_device *nvmem) · line 485

Quoted 7 lines
drivers/nvmem/core.c +3 -1
@@ -480,7 +480,9 @@ static int nvmem_populate_sysfs_cells(struct nvmem_device *nvmem)
 	/* Initialize each attribute to take the name and size of the cell */
 	list_for_each_entry(entry, &nvmem->cells, node) {
 		sysfs_bin_attr_init(&attrs[i]);
-		attrs[i].attr.name = devm_kstrdup(&nvmem->dev, entry->name, GFP_KERNEL);
+		attrs[i].attr.name = devm_kasprintf(&nvmem->dev, GFP_KERNEL,
+						    "%s@%d", entry->name,
+						    entry->offset);

Shouldn't we use %s@%x instead to match the DT descriptions?

drivers/nvmem/core.c static int nvmem_populate_sysfs_cells(struct nvmem_device *nvmem) · line 488

Quoted 3 lines
drivers/nvmem/core.c +0 -0
 		attrs[i].attr.mode = 0444;
 		attrs[i].size = entry->bytes;
 		attrs[i].read = &nvmem_cell_attr_read;

I plan another version of the series which triggered these patches, if you don't mind I will squash patch 1 into my patches and pick this one as a preparation change (likely with the above fix if you agree and without the Fixes tag).

Thanks,
Miquèl

#3 lore raw

Hi Miquel,

Quoted 15 lines · Miquel Raynal

Hi Daniel,

[email protected] wrote on Tue, 18 Jul 2023 14:55:57 +0100:

Quoted 11 lines

The device tree node names are not required to be unique. Append the offset to the name to make cell nodes with identical names become accessible via sysfs and avoid kernel stackdump caused by
sysfs: cannot create duplicate filename '...'

Fixes 757f8b3835c9 ("nvmem: core: Expose cells through sysfs")
---
 drivers/nvmem/core.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
Quoted 14 lines

drivers/nvmem/core.c static int nvmem_populate_sysfs_cells(struct nvmem_device *nvmem) · line 485

Quoted 12 lines
drivers/nvmem/core.c +3 -1
index 70e951088826d..90fe9dc30f8ba 100644
@@ -480,7 +480,9 @@ static int nvmem_populate_sysfs_cells(struct nvmem_device *nvmem)
 	/* Initialize each attribute to take the name and size of the cell */
 	list_for_each_entry(entry, &nvmem->cells, node) {
 		sysfs_bin_attr_init(&attrs[i]);
-		attrs[i].attr.name = devm_kstrdup(&nvmem->dev, entry->name, GFP_KERNEL);
+		attrs[i].attr.name = devm_kasprintf(&nvmem->dev, GFP_KERNEL,
+						    "%s@%d", entry->name,
+						    entry->offset);

Shouldn't we use %s@%x instead to match the DT descriptions?

True, I agree.

Quoted 9 lines

drivers/nvmem/core.c static int nvmem_populate_sysfs_cells(struct nvmem_device *nvmem) · line 488

Quoted 4 lines
drivers/nvmem/core.c +0 -0
 		attrs[i].attr.mode = 0444;
 		attrs[i].size = entry->bytes;
 		attrs[i].read = &nvmem_cell_attr_read;

I plan another version of the series which triggered these patches, if you don't mind I will squash patch 1 into my patches and pick this one as a preparation change (likely with the above fix if you agree and without the Fixes tag).

Yes, sure, please go ahead.

Cheers

Daniel

Quoted 3 lines

Thanks,
Miquèl