Skip to contentSkip to conversation

of: Make OF framebuffer device names unique

PATCH New Rob Herring 1 participant 1 message Feb 1, 2023 Device tree

lore
Share & tools
lore

Rob Herring

author maintainer
#0 lore raw

PATCH v4 1/1 of: Make OF framebuffer device names unique

From: Michal Suchanek <[email protected]>

Since Linux 5.19 this error is observed:

sysfs: cannot create duplicate filename '/devices/platform/of-display'

This is because multiple devices with the same name 'of-display' are created on the same bus. Update the code to create numbered device names for the displays.

Also, fix a node refcounting issue when exiting the boot display loop.

cc: [email protected]
References: https://bugzilla.kernel.org/show_bug.cgi?id=216095

Fixes 52b1b46c39ae ("of: Create platform devices for OF framebuffers")
[robh: Rework to avoid node refcount leaks]
---
 drivers/of/platform.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
drivers/of/platform.c +10 -2
index 81c8c227ab6b..b3878a98d27f 100644
@@ -525,6 +525,7 @@ static int __init of_platform_default_populate_init(void)
 	if (IS_ENABLED(CONFIG_PPC)) {
 		struct device_node *boot_display = NULL;
 		struct platform_device *dev;
+		int display_number = 0;
 		int ret;
 
 		/* Check if we have a MacOS display without a node spec */
@@ -555,16 +556,23 @@ static int __init of_platform_default_populate_init(void)
 			if (!of_get_property(node, "linux,opened", NULL) ||
 			    !of_get_property(node, "linux,boot-display", NULL))
 				continue;
-			dev = of_platform_device_create(node, "of-display", NULL);
+			dev = of_platform_device_create(node, "of-display.0", NULL);
+			of_node_put(node);
 			if (WARN_ON(!dev))
 				return -ENOMEM;
 			boot_display = node;
+			display_number++;
 			break;
 		}
 		for_each_node_by_type(node, "display") {
+			char buf[14];
+			const char *of_display_format = "of-display.%d";
+
 			if (!of_get_property(node, "linux,opened", NULL) || node == boot_display)
 				continue;
-			of_platform_device_create(node, "of-display", NULL);
+			ret = snprintf(buf, sizeof(buf), of_display_format, display_number++);
+			if (ret < sizeof(buf))
+				of_platform_device_create(node, buf, NULL);
 		}
 
 	} else {
Signature · 1 line
2.39.0