Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

of: Make OF framebuffer device names unique

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: linuxppc-dev@lists.ozlabs.org
References: https://bugzilla.kernel.org/show_bug.cgi?id=216095
Fixes: 52b1b46c39ae ("of: Create platform devices for OF framebuffers")
Reported-by: Erhard F. <erhard_f@mailbox.org>
Suggested-by: Thomas Zimmermann <tzimmermann@suse.de>
Signed-off-by: Michal Suchanek <msuchanek@suse.de>
Link: https://lore.kernel.org/r/20230201162247.3575506-1-robh@kernel.org
[robh: Rework to avoid node refcount leaks]
Signed-off-by: Rob Herring <robh@kernel.org>

authored by

Michal Suchanek and committed by
Rob Herring
241d2fb5 064e32dc

+10 -2
+10 -2
drivers/of/platform.c
··· 525 525 if (IS_ENABLED(CONFIG_PPC)) { 526 526 struct device_node *boot_display = NULL; 527 527 struct platform_device *dev; 528 + int display_number = 0; 528 529 int ret; 529 530 530 531 /* Check if we have a MacOS display without a node spec */ ··· 556 555 if (!of_get_property(node, "linux,opened", NULL) || 557 556 !of_get_property(node, "linux,boot-display", NULL)) 558 557 continue; 559 - dev = of_platform_device_create(node, "of-display", NULL); 558 + dev = of_platform_device_create(node, "of-display.0", NULL); 559 + of_node_put(node); 560 560 if (WARN_ON(!dev)) 561 561 return -ENOMEM; 562 562 boot_display = node; 563 + display_number++; 563 564 break; 564 565 } 565 566 for_each_node_by_type(node, "display") { 567 + char buf[14]; 568 + const char *of_display_format = "of-display.%d"; 569 + 566 570 if (!of_get_property(node, "linux,opened", NULL) || node == boot_display) 567 571 continue; 568 - of_platform_device_create(node, "of-display", NULL); 572 + ret = snprintf(buf, sizeof(buf), of_display_format, display_number++); 573 + if (ret < sizeof(buf)) 574 + of_platform_device_create(node, buf, NULL); 569 575 } 570 576 571 577 } else {