Message ID | 20230119095323.4659-1-msuchanek@suse.de |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp240200wrn; Thu, 19 Jan 2023 02:04:09 -0800 (PST) X-Google-Smtp-Source: AMrXdXs71aA4JOMIwy0E4vS74oT12cFqK8WL0TRd+6a6jt55qrqF8o7tUAyeJUkyR3Olv3ZUEpJ3 X-Received: by 2002:a17:906:a21a:b0:877:7157:9358 with SMTP id r26-20020a170906a21a00b0087771579358mr1997148ejy.10.1674122649317; Thu, 19 Jan 2023 02:04:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674122649; cv=none; d=google.com; s=arc-20160816; b=sP/4dWImyM9Bf9uJg+92oDz6vndRFPMAaUR90lbEgFFHoCt0/ZTHOKr7vtuQtk/mgA xUH9kE1H+w6QDvDRY8Y9Eq7ZxvMpQgTEq5ineGeIAeXMPI9tk9MnZE0q+FLryu6tP0uu 1YR6gBLW0Sr5geUvteoxoV6jWqDM35Cvyyf+XIwpcUYIEC6wS6TGRHpLrWOMby8Lv5oH Vunu9KK6fDsOSq+/bEHNGbV3qCxdJ18YTJR1pXF/VZvBWHSU5nXbjWRfd4qNnPh/GFsm UT9cj2T3hpd9EIIzpGkxKhwbFFPyySwc1cqob1Y10PWQab6YZoK5txbS96IgmGXeJFm2 EIfQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:dkim-signature; bh=K5Wjtf9hLzRkuQgSxBaDv2x2hWptBx8DnMTdLdxBFys=; b=XnwaKPLT1eGQRfHwB3//v3i2aQbbTPVH4IiOA/ViXwNrnVa0pTvpkEMZCLk4KP85pu cdfziypXE/GTB0u6KiG0zXR+hasoqQpx+9sXoZPHpcAl2ElYqYY0wp1S9TXh78/TAoLi Do/DX+6FwBE9/pOv0NeZzrqcTKTclMy5kq27qdhvKiygnjygxakxltYfnRk5LYEzITm0 Zuvq4tH/cmOUE3H17n0RbKBO20SutyHFjI50ZhLWIOH/xuxUrPhuzv9u9xVY4WDA9jgY 89XxQFiIVgm6oP/oFiiyIjnWLQZfWoAnT6CGlindtYf4mh9LXpecjeRhWJ0FlWydFN6b +LzA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=JmeRmKIx; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519 header.b=W4gz9+a1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gb36-20020a170907962400b0086c7dc4fd9bsi21095102ejc.538.2023.01.19.02.03.45; Thu, 19 Jan 2023 02:04:09 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=JmeRmKIx; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519 header.b=W4gz9+a1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230194AbjASJxv (ORCPT <rfc822;pfffrao@gmail.com> + 99 others); Thu, 19 Jan 2023 04:53:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33706 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229515AbjASJxs (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 19 Jan 2023 04:53:48 -0500 Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 315D15D106; Thu, 19 Jan 2023 01:53:47 -0800 (PST) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id D8E7E38562; Thu, 19 Jan 2023 09:53:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1674122025; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=K5Wjtf9hLzRkuQgSxBaDv2x2hWptBx8DnMTdLdxBFys=; b=JmeRmKIxA6LcTyfKL46wUKQQNW++j5YCwI2EWzrWqc5lJBCJIisF2fK988F9sSL9hOiPLb 7VDN++/nwTj39/JeiH2rRbyjjJ3Lybm1hAjvfdiXu1dj6hmt2KO/8opk+B/kYdfQBKc4K1 hK5CGO2UJtE0+0SnXEbldehQ/6TlDAY= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1674122025; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=K5Wjtf9hLzRkuQgSxBaDv2x2hWptBx8DnMTdLdxBFys=; b=W4gz9+a1bRbUTmeUmj43HT5F78l511dttU0eg+3fYuLsqWanKN8UgFIovvKDV5LDR+eYhH +5jwqSM1gnnDzMDw== Received: from kitsune.suse.cz (kitsune.suse.cz [10.100.12.127]) by relay2.suse.de (Postfix) with ESMTP id A9E912C141; Thu, 19 Jan 2023 09:53:45 +0000 (UTC) From: Michal Suchanek <msuchanek@suse.de> To: "Erhard F." <erhard_f@mailbox.org>, Thomas Zimmermann <tzimmermann@suse.de>, Rob Herring <robh+dt@kernel.org> Cc: Michal Suchanek <msuchanek@suse.de>, "open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE" <devicetree@vger.kernel.org>, linuxppc-dev@lists.ozlabs.org, Javier Martinez Canillas <javierm@redhat.com>, open list <linux-kernel@vger.kernel.org>, Frank Rowand <frowand.list@gmail.com> Subject: [PATCH v2] of: Fix of platform build on powerpc due to bad of disaply code Date: Thu, 19 Jan 2023 10:53:23 +0100 Message-Id: <20230119095323.4659-1-msuchanek@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230118215045.5551-1-msuchanek@suse.de> References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1755399609663748161?= X-GMAIL-MSGID: =?utf-8?q?1755444831152122433?= |
Series |
[v2] of: Fix of platform build on powerpc due to bad of disaply code
|
|
Commit Message
Michal Suchánek
Jan. 19, 2023, 9:53 a.m. UTC
The commit 2d681d6a23a1 ("of: Make of framebuffer devices unique")
breaks build because of wrong argument to snprintf. That certainly
avoids the runtime error but is not the intended outcome.
Also use standard device name format of-display.N for all created
devices.
Fixes: 2d681d6a23a1 ("of: Make of framebuffer devices unique")
Signed-off-by: Michal Suchanek <msuchanek@suse.de>
---
v2: Update the device name format
---
drivers/of/platform.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
Comments
Am 19.01.23 um 10:53 schrieb Michal Suchanek: > The commit 2d681d6a23a1 ("of: Make of framebuffer devices unique") > breaks build because of wrong argument to snprintf. That certainly > avoids the runtime error but is not the intended outcome. > > Also use standard device name format of-display.N for all created > devices. > > Fixes: 2d681d6a23a1 ("of: Make of framebuffer devices unique") > Signed-off-by: Michal Suchanek <msuchanek@suse.de> Reviewed-by: Thomas Zimmermann <tzimmermann@suse.de> Thanks again for taking care of this issue. > --- > v2: Update the device name format > --- > drivers/of/platform.c | 12 ++++++++---- > 1 file changed, 8 insertions(+), 4 deletions(-) > > diff --git a/drivers/of/platform.c b/drivers/of/platform.c > index f2a5d679a324..8c1b1de22036 100644 > --- a/drivers/of/platform.c > +++ b/drivers/of/platform.c > @@ -525,7 +525,9 @@ 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 = 1; > + int display_number = 0; > + char buf[14]; > + char *of_display_format = "of-display.%d"; > int ret; > > /* Check if we have a MacOS display without a node spec */ > @@ -556,7 +558,10 @@ 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); > + ret = snprintf(buf, sizeof(buf), of_display_format, display_number++); > + if (ret >= sizeof(buf)) > + continue; > + dev = of_platform_device_create(node, buf, NULL); > if (WARN_ON(!dev)) > return -ENOMEM; > boot_display = node; > @@ -564,10 +569,9 @@ static int __init of_platform_default_populate_init(void) > } > > for_each_node_by_type(node, "display") { > - char *buf[14]; > if (!of_get_property(node, "linux,opened", NULL) || node == boot_display) > continue; > - ret = snprintf(buf, "of-display-%d", display_number++); > + ret = snprintf(buf, sizeof(buf), of_display_format, display_number++); > if (ret >= sizeof(buf)) > continue; > of_platform_device_create(node, buf, NULL); -- Thomas Zimmermann Graphics Driver Developer SUSE Software Solutions Germany GmbH Maxfeldstr. 5, 90409 Nürnberg, Germany (HRB 36809, AG Nürnberg) Geschäftsführer: Ivo Totev
Hello, On Thu, Jan 19, 2023 at 10:24:07AM +0000, Christophe Leroy wrote: > > > Le 19/01/2023 à 10:53, Michal Suchanek a écrit : > > The commit 2d681d6a23a1 ("of: Make of framebuffer devices unique") > > breaks build because of wrong argument to snprintf. That certainly > > avoids the runtime error but is not the intended outcome. > > > > Also use standard device name format of-display.N for all created > > devices. > > > > Fixes: 2d681d6a23a1 ("of: Make of framebuffer devices unique") > > Signed-off-by: Michal Suchanek <msuchanek@suse.de> > > --- > > v2: Update the device name format > > --- > > drivers/of/platform.c | 12 ++++++++---- > > 1 file changed, 8 insertions(+), 4 deletions(-) > > > > diff --git a/drivers/of/platform.c b/drivers/of/platform.c > > index f2a5d679a324..8c1b1de22036 100644 > > --- a/drivers/of/platform.c > > +++ b/drivers/of/platform.c > > @@ -525,7 +525,9 @@ 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 = 1; > > + int display_number = 0; > > + char buf[14]; > > Can you declare that in the for block where it is used instead ? No, there are two for blocks. > > > + char *of_display_format = "of-display.%d"; > > Should be const ? Yes, could be. > > > int ret; > > > > /* Check if we have a MacOS display without a node spec */ > > @@ -556,7 +558,10 @@ 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); > > + ret = snprintf(buf, sizeof(buf), of_display_format, display_number++); > > + if (ret >= sizeof(buf)) > > + continue; > > > Can you make buf big enough to avoid that ? It would be a bit fragile that way. The buffer would have to theoretically accomodate "of-display.-9223372036854775808", and any change to the format requires recalculating the length, by hand. Of course, the memory would run out way before allocating that many devices so it's kind of pointless to try and accomodate all possible device numbers. > > And by the way could it be called something else than 'buf' ? > > See exemple here : > https://elixir.bootlin.com/linux/v6.1/source/drivers/fsi/fsi-occ.c#L690 Yes, that is quite possible. Nonetheless, just like 'ret' generic variable names also work. Thanks Michal
On Thu, 19 Jan 2023 10:53:23 +0100 Michal Suchanek <msuchanek@suse.de> wrote: > The commit 2d681d6a23a1 ("of: Make of framebuffer devices unique") > breaks build because of wrong argument to snprintf. That certainly > avoids the runtime error but is not the intended outcome. > > Also use standard device name format of-display.N for all created > devices. > > Fixes: 2d681d6a23a1 ("of: Make of framebuffer devices unique") > Signed-off-by: Michal Suchanek <msuchanek@suse.de> > --- > v2: Update the device name format Hi Michal! Just tested your 'of: Make of framebuffer devices unique' + 'v2 of: Fix of platform build on powerpc due to bad of disaply code' on my G4 and can confirm they fix the original issue (https://bugzilla.kernel.org/show_bug.cgi?id=216095). Thanks! Also ofdrm gets loaded now without error messages: # modprobe -v ofdrm insmod /lib/modules/6.2.0-rc4-PMacG4+/kernel/drivers/video/fbdev/core/cfbcopyarea.ko insmod /lib/modules/6.2.0-rc4-PMacG4+/kernel/drivers/video/fbdev/core/sysimgblt.ko insmod /lib/modules/6.2.0-rc4-PMacG4+/kernel/drivers/video/fbdev/core/sysfillrect.ko insmod /lib/modules/6.2.0-rc4-PMacG4+/kernel/drivers/video/fbdev/core/cfbimgblt.ko insmod /lib/modules/6.2.0-rc4-PMacG4+/kernel/drivers/video/fbdev/core/syscopyarea.ko insmod /lib/modules/6.2.0-rc4-PMacG4+/kernel/drivers/video/fbdev/core/cfbfillrect.ko insmod /lib/modules/6.2.0-rc4-PMacG4+/kernel/drivers/gpu/drm/drm_kms_helper.ko insmod /lib/modules/6.2.0-rc4-PMacG4+/kernel/drivers/gpu/drm/drm_shmem_helper.ko insmod /lib/modules/6.2.0-rc4-PMacG4+/kernel/drivers/gpu/drm/tiny/ofdrm.ko However I get no monitor output yet, despite ofdrm is loaded: # lsmod | grep -i drm ofdrm 9736 0 drm_shmem_helper 5704 1 ofdrm drm_kms_helper 101736 1 ofdrm cfbfillrect 2896 1 drm_kms_helper syscopyarea 2400 1 drm_kms_helper cfbimgblt 2256 1 drm_kms_helper sysfillrect 2920 1 drm_kms_helper sysimgblt 2296 1 drm_kms_helper cfbcopyarea 2376 1 drm_kms_helper drm 288960 3 drm_shmem_helper,ofdrm,drm_kms_helper drm_panel_orientation_quirks 16 1 drm I use DRM [=m], DRM_OFDRM [=m], DRM_RADEON [=n], DRM_FBDEV_EMULATION [=y], FB [=y] and FB_OF [=n] in my kernel test .config. As far as I understand DRM_OFDRM and FB_OF would be mutually exclusive? Also does not seem to make a difference whether FB_SIMPLE [=y] is set. Regards, Erhard
Hi Am 19.01.23 um 11:24 schrieb Christophe Leroy: > > > Le 19/01/2023 à 10:53, Michal Suchanek a écrit : >> The commit 2d681d6a23a1 ("of: Make of framebuffer devices unique") >> breaks build because of wrong argument to snprintf. That certainly >> avoids the runtime error but is not the intended outcome. >> >> Also use standard device name format of-display.N for all created >> devices. >> >> Fixes: 2d681d6a23a1 ("of: Make of framebuffer devices unique") >> Signed-off-by: Michal Suchanek <msuchanek@suse.de> >> --- >> v2: Update the device name format >> --- >> drivers/of/platform.c | 12 ++++++++---- >> 1 file changed, 8 insertions(+), 4 deletions(-) >> >> diff --git a/drivers/of/platform.c b/drivers/of/platform.c >> index f2a5d679a324..8c1b1de22036 100644 >> --- a/drivers/of/platform.c >> +++ b/drivers/of/platform.c >> @@ -525,7 +525,9 @@ 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 = 1; >> + int display_number = 0; >> + char buf[14]; > > Can you declare that in the for block where it is used instead ? > >> + char *of_display_format = "of-display.%d"; > > Should be const ? That should be static const of_display_format[] = then > >> int ret; >> >> /* Check if we have a MacOS display without a node spec */ >> @@ -556,7 +558,10 @@ 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); >> + ret = snprintf(buf, sizeof(buf), of_display_format, display_number++); >> + if (ret >= sizeof(buf)) >> + continue; > > > Can you make buf big enough to avoid that ? > > And by the way could it be called something else than 'buf' ? > > See exemple here : > https://elixir.bootlin.com/linux/v6.1/source/drivers/fsi/fsi-occ.c#L690 > > >> + dev = of_platform_device_create(node, buf, NULL); >> if (WARN_ON(!dev)) >> return -ENOMEM; >> boot_display = node; >> @@ -564,10 +569,9 @@ static int __init of_platform_default_populate_init(void) >> } >> >> for_each_node_by_type(node, "display") { >> - char *buf[14]; >> if (!of_get_property(node, "linux,opened", NULL) || node == boot_display) >> continue; >> - ret = snprintf(buf, "of-display-%d", display_number++); >> + ret = snprintf(buf, sizeof(buf), of_display_format, display_number++); >> if (ret >= sizeof(buf)) >> continue; >> of_platform_device_create(node, buf, NULL); -- Thomas Zimmermann Graphics Driver Developer SUSE Software Solutions Germany GmbH Maxfeldstr. 5, 90409 Nürnberg, Germany (HRB 36809, AG Nürnberg) Geschäftsführer: Ivo Totev
On Thu, Jan 19, 2023 at 02:11:13PM +0100, Thomas Zimmermann wrote: > Hi > > Am 19.01.23 um 11:24 schrieb Christophe Leroy: > > > > > > Le 19/01/2023 à 10:53, Michal Suchanek a écrit : > > > The commit 2d681d6a23a1 ("of: Make of framebuffer devices unique") > > > breaks build because of wrong argument to snprintf. That certainly > > > avoids the runtime error but is not the intended outcome. > > > > > > Also use standard device name format of-display.N for all created > > > devices. > > > > > > Fixes: 2d681d6a23a1 ("of: Make of framebuffer devices unique") > > > Signed-off-by: Michal Suchanek <msuchanek@suse.de> > > > --- > > > v2: Update the device name format > > > --- > > > drivers/of/platform.c | 12 ++++++++---- > > > 1 file changed, 8 insertions(+), 4 deletions(-) > > > > > > diff --git a/drivers/of/platform.c b/drivers/of/platform.c > > > index f2a5d679a324..8c1b1de22036 100644 > > > --- a/drivers/of/platform.c > > > +++ b/drivers/of/platform.c > > > @@ -525,7 +525,9 @@ 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 = 1; > > > + int display_number = 0; > > > + char buf[14]; > > > > Can you declare that in the for block where it is used instead ? > > > > > + char *of_display_format = "of-display.%d"; > > > > Should be const ? > > That should be static const of_display_format[] = then Why? It sounds completely fine to have a const pointer to a string constatnt. Thanks Michal > > > > > > int ret; > > > /* Check if we have a MacOS display without a node spec */ > > > @@ -556,7 +558,10 @@ 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); > > > + ret = snprintf(buf, sizeof(buf), of_display_format, display_number++); > > > + if (ret >= sizeof(buf)) > > > + continue; > > > > > > Can you make buf big enough to avoid that ? > > > > And by the way could it be called something else than 'buf' ? > > > > See exemple here : > > https://elixir.bootlin.com/linux/v6.1/source/drivers/fsi/fsi-occ.c#L690 > > > > > > > + dev = of_platform_device_create(node, buf, NULL); > > > if (WARN_ON(!dev)) > > > return -ENOMEM; > > > boot_display = node; > > > @@ -564,10 +569,9 @@ static int __init of_platform_default_populate_init(void) > > > } > > > for_each_node_by_type(node, "display") { > > > - char *buf[14]; > > > if (!of_get_property(node, "linux,opened", NULL) || node == boot_display) > > > continue; > > > - ret = snprintf(buf, "of-display-%d", display_number++); > > > + ret = snprintf(buf, sizeof(buf), of_display_format, display_number++); > > > if (ret >= sizeof(buf)) > > > continue; > > > of_platform_device_create(node, buf, NULL); > > -- > Thomas Zimmermann > Graphics Driver Developer > SUSE Software Solutions Germany GmbH > Maxfeldstr. 5, 90409 Nürnberg, Germany > (HRB 36809, AG Nürnberg) > Geschäftsführer: Ivo Totev
On Thu, Jan 19, 2023 at 3:53 AM Michal Suchanek <msuchanek@suse.de> wrote: > > The commit 2d681d6a23a1 ("of: Make of framebuffer devices unique") > breaks build because of wrong argument to snprintf. That certainly > avoids the runtime error but is not the intended outcome. > > Also use standard device name format of-display.N for all created > devices. > > Fixes: 2d681d6a23a1 ("of: Make of framebuffer devices unique") > Signed-off-by: Michal Suchanek <msuchanek@suse.de> > --- > v2: Update the device name format > --- > drivers/of/platform.c | 12 ++++++++---- > 1 file changed, 8 insertions(+), 4 deletions(-) As this is the only fix I have queued, if you respin, send the original fix with fixes squashed. Rob
Hi Am 19.01.23 um 14:23 schrieb Michal Suchánek: > On Thu, Jan 19, 2023 at 02:11:13PM +0100, Thomas Zimmermann wrote: >> Hi >> >> Am 19.01.23 um 11:24 schrieb Christophe Leroy: >>> >>> >>> Le 19/01/2023 à 10:53, Michal Suchanek a écrit : >>>> The commit 2d681d6a23a1 ("of: Make of framebuffer devices unique") >>>> breaks build because of wrong argument to snprintf. That certainly >>>> avoids the runtime error but is not the intended outcome. >>>> >>>> Also use standard device name format of-display.N for all created >>>> devices. >>>> >>>> Fixes: 2d681d6a23a1 ("of: Make of framebuffer devices unique") >>>> Signed-off-by: Michal Suchanek <msuchanek@suse.de> >>>> --- >>>> v2: Update the device name format >>>> --- >>>> drivers/of/platform.c | 12 ++++++++---- >>>> 1 file changed, 8 insertions(+), 4 deletions(-) >>>> >>>> diff --git a/drivers/of/platform.c b/drivers/of/platform.c >>>> index f2a5d679a324..8c1b1de22036 100644 >>>> --- a/drivers/of/platform.c >>>> +++ b/drivers/of/platform.c >>>> @@ -525,7 +525,9 @@ 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 = 1; >>>> + int display_number = 0; >>>> + char buf[14]; >>> >>> Can you declare that in the for block where it is used instead ? >>> >>>> + char *of_display_format = "of-display.%d"; >>> >>> Should be const ? >> >> That should be static const of_display_format[] = then > > Why? It sounds completely fine to have a const pointer to a string > constatnt. Generally speaking: 'static' because your const pointer is then not a local variable, so it takes pressure off the stack. For global variables, you don't want them to show up in any linker symbol tables. The string "of-display.%d" is stored as an array in the ELF data section. And your char pointer is a reference to that array. For static pointers, these indirections take CPU cycles to update when the loader has to relocate sections. If you declare of_display_format[] directly as array, you avoid the reference and work directly with the array. Of course, this is a kernel module and the string is self-contained within the function. So the compiler can probably detect that and optimize the code to be like the 'static const []' version. It's still good to follow best practices, as someone might copy from this function. Best regards Thomas > > Thanks > > Michal > >> >>> >>>> int ret; >>>> /* Check if we have a MacOS display without a node spec */ >>>> @@ -556,7 +558,10 @@ 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); >>>> + ret = snprintf(buf, sizeof(buf), of_display_format, display_number++); >>>> + if (ret >= sizeof(buf)) >>>> + continue; >>> >>> >>> Can you make buf big enough to avoid that ? >>> >>> And by the way could it be called something else than 'buf' ? >>> >>> See exemple here : >>> https://elixir.bootlin.com/linux/v6.1/source/drivers/fsi/fsi-occ.c#L690 >>> >>> >>>> + dev = of_platform_device_create(node, buf, NULL); >>>> if (WARN_ON(!dev)) >>>> return -ENOMEM; >>>> boot_display = node; >>>> @@ -564,10 +569,9 @@ static int __init of_platform_default_populate_init(void) >>>> } >>>> for_each_node_by_type(node, "display") { >>>> - char *buf[14]; >>>> if (!of_get_property(node, "linux,opened", NULL) || node == boot_display) >>>> continue; >>>> - ret = snprintf(buf, "of-display-%d", display_number++); >>>> + ret = snprintf(buf, sizeof(buf), of_display_format, display_number++); >>>> if (ret >= sizeof(buf)) >>>> continue; >>>> of_platform_device_create(node, buf, NULL); >> >> -- >> Thomas Zimmermann >> Graphics Driver Developer >> SUSE Software Solutions Germany GmbH >> Maxfeldstr. 5, 90409 Nürnberg, Germany >> (HRB 36809, AG Nürnberg) >> Geschäftsführer: Ivo Totev > > > -- Thomas Zimmermann Graphics Driver Developer SUSE Software Solutions Germany GmbH Maxfeldstr. 5, 90409 Nürnberg, Germany (HRB 36809, AG Nürnberg) Geschäftsführer: Ivo Totev
Hello, On Thu, Jan 19, 2023 at 04:20:57PM +0100, Thomas Zimmermann wrote: > Hi > > Am 19.01.23 um 14:23 schrieb Michal Suchánek: > > On Thu, Jan 19, 2023 at 02:11:13PM +0100, Thomas Zimmermann wrote: > > > Hi > > > > > > Am 19.01.23 um 11:24 schrieb Christophe Leroy: > > > > > > > > > > > > Le 19/01/2023 à 10:53, Michal Suchanek a écrit : > > > > > The commit 2d681d6a23a1 ("of: Make of framebuffer devices unique") > > > > > breaks build because of wrong argument to snprintf. That certainly > > > > > avoids the runtime error but is not the intended outcome. > > > > > > > > > > Also use standard device name format of-display.N for all created > > > > > devices. > > > > > > > > > > Fixes: 2d681d6a23a1 ("of: Make of framebuffer devices unique") > > > > > Signed-off-by: Michal Suchanek <msuchanek@suse.de> > > > > > --- > > > > > v2: Update the device name format > > > > > --- > > > > > drivers/of/platform.c | 12 ++++++++---- > > > > > 1 file changed, 8 insertions(+), 4 deletions(-) > > > > > > > > > > diff --git a/drivers/of/platform.c b/drivers/of/platform.c > > > > > index f2a5d679a324..8c1b1de22036 100644 > > > > > --- a/drivers/of/platform.c > > > > > +++ b/drivers/of/platform.c > > > > > @@ -525,7 +525,9 @@ 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 = 1; > > > > > + int display_number = 0; > > > > > + char buf[14]; > > > > > > > > Can you declare that in the for block where it is used instead ? > > > > > > > > > + char *of_display_format = "of-display.%d"; > > > > > > > > Should be const ? > > > > > > That should be static const of_display_format[] = then > > > > Why? It sounds completely fine to have a const pointer to a string > > constatnt. > > Generally speaking: > > 'static' because your const pointer is then not a local variable, so it > takes pressure off the stack. For global variables, you don't want them to > show up in any linker symbol tables. This sounds a lot like an exemplar case of premature optimization. A simplistic compiler might do exactly what you say, and allocate a slot for the variable on the stack the moment the function is entered. However, in real compilers there is no stack pressure from having a local variable: - the compiler can put the variable into a register - it can completely omit the variable before and after it's actually used which is that specific function call > The string "of-display.%d" is stored as an array in the ELF data section. > And your char pointer is a reference to that array. For static pointers, > these indirections take CPU cycles to update when the loader has to relocate Provided that the char pointer ever exists in the compiled code. Its address is not taken so it does not need to. > sections. If you declare of_display_format[] directly as array, you avoid > the reference and work directly with the array. > > Of course, this is a kernel module and the string is self-contained within > the function. So the compiler can probably detect that and optimize the code > to be like the 'static const []' version. It's still good to follow best > practices, as someone might copy from this function. If it could not detect it there would be a lot of trouble all around. Thanks Michal
Hi Am 20.01.23 um 12:27 schrieb Michal Suchánek: > Hello, > > On Thu, Jan 19, 2023 at 04:20:57PM +0100, Thomas Zimmermann wrote: >> Hi >> >> Am 19.01.23 um 14:23 schrieb Michal Suchánek: >>> On Thu, Jan 19, 2023 at 02:11:13PM +0100, Thomas Zimmermann wrote: >>>> Hi >>>> >>>> Am 19.01.23 um 11:24 schrieb Christophe Leroy: >>>>> >>>>> >>>>> Le 19/01/2023 à 10:53, Michal Suchanek a écrit : >>>>>> The commit 2d681d6a23a1 ("of: Make of framebuffer devices unique") >>>>>> breaks build because of wrong argument to snprintf. That certainly >>>>>> avoids the runtime error but is not the intended outcome. >>>>>> >>>>>> Also use standard device name format of-display.N for all created >>>>>> devices. >>>>>> >>>>>> Fixes: 2d681d6a23a1 ("of: Make of framebuffer devices unique") >>>>>> Signed-off-by: Michal Suchanek <msuchanek@suse.de> >>>>>> --- >>>>>> v2: Update the device name format >>>>>> --- >>>>>> drivers/of/platform.c | 12 ++++++++---- >>>>>> 1 file changed, 8 insertions(+), 4 deletions(-) >>>>>> >>>>>> diff --git a/drivers/of/platform.c b/drivers/of/platform.c >>>>>> index f2a5d679a324..8c1b1de22036 100644 >>>>>> --- a/drivers/of/platform.c >>>>>> +++ b/drivers/of/platform.c >>>>>> @@ -525,7 +525,9 @@ 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 = 1; >>>>>> + int display_number = 0; >>>>>> + char buf[14]; >>>>> >>>>> Can you declare that in the for block where it is used instead ? >>>>> >>>>>> + char *of_display_format = "of-display.%d"; >>>>> >>>>> Should be const ? >>>> >>>> That should be static const of_display_format[] = then >>> >>> Why? It sounds completely fine to have a const pointer to a string >>> constatnt. >> >> Generally speaking: >> >> 'static' because your const pointer is then not a local variable, so it >> takes pressure off the stack. For global variables, you don't want them to >> show up in any linker symbol tables. > > This sounds a lot like an exemplar case of premature optimization. > A simplistic compiler might do exactly what you say, and allocate a slot > for the variable on the stack the moment the function is entered. > > However, in real compilers there is no stack pressure from having a > local variable: > - the compiler can put the variable into a register > - it can completely omit the variable before and after it's actually > used which is that specific function call > >> The string "of-display.%d" is stored as an array in the ELF data section. >> And your char pointer is a reference to that array. For static pointers, >> these indirections take CPU cycles to update when the loader has to relocate > > Provided that the char pointer ever exists in the compiled code. Its > address is not taken so it does not need to. > >> sections. If you declare of_display_format[] directly as array, you avoid >> the reference and work directly with the array. >> >> Of course, this is a kernel module and the string is self-contained within >> the function. So the compiler can probably detect that and optimize the code >> to be like the 'static const []' version. It's still good to follow best >> practices, as someone might copy from this function. > > If it could not detect it there would be a lot of trouble all around. The issues definitely exist in userspace code. Kernel modules are simpler, so compiler optimization is easier. But I'm not really trying to make a technical argument. My point here is that someone might read your code and duplicate the pattern. That's not unreasonable: it's core Linux code, so it can be assumed to be good (or at least not bad). But your current code teaches the reader a bad practices, which should be avoided. It is better to do the correct thing, even if it makes no difference to the compiled code. Best regards Thomas > > Thanks > > Michal -- Thomas Zimmermann Graphics Driver Developer SUSE Software Solutions Germany GmbH Maxfeldstr. 5, 90409 Nürnberg, Germany (HRB 36809, AG Nürnberg) Geschäftsführer: Ivo Totev
On Fri, Jan 20, 2023 at 12:39:23PM +0100, Thomas Zimmermann wrote: > Hi > > Am 20.01.23 um 12:27 schrieb Michal Suchánek: > > Hello, > > > > On Thu, Jan 19, 2023 at 04:20:57PM +0100, Thomas Zimmermann wrote: > > > Hi > > > > > > Am 19.01.23 um 14:23 schrieb Michal Suchánek: > > > > On Thu, Jan 19, 2023 at 02:11:13PM +0100, Thomas Zimmermann wrote: > > > > > Hi > > > > > > > > > > Am 19.01.23 um 11:24 schrieb Christophe Leroy: > > > > > > > > > > > > > > > > > > Le 19/01/2023 à 10:53, Michal Suchanek a écrit : > > > > > > > The commit 2d681d6a23a1 ("of: Make of framebuffer devices unique") > > > > > > > breaks build because of wrong argument to snprintf. That certainly > > > > > > > avoids the runtime error but is not the intended outcome. > > > > > > > > > > > > > > Also use standard device name format of-display.N for all created > > > > > > > devices. > > > > > > > > > > > > > > Fixes: 2d681d6a23a1 ("of: Make of framebuffer devices unique") > > > > > > > Signed-off-by: Michal Suchanek <msuchanek@suse.de> > > > > > > > --- > > > > > > > v2: Update the device name format > > > > > > > --- > > > > > > > drivers/of/platform.c | 12 ++++++++---- > > > > > > > 1 file changed, 8 insertions(+), 4 deletions(-) > > > > > > > > > > > > > > diff --git a/drivers/of/platform.c b/drivers/of/platform.c > > > > > > > index f2a5d679a324..8c1b1de22036 100644 > > > > > > > --- a/drivers/of/platform.c > > > > > > > +++ b/drivers/of/platform.c > > > > > > > @@ -525,7 +525,9 @@ 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 = 1; > > > > > > > + int display_number = 0; > > > > > > > + char buf[14]; > > > > > > > > > > > > Can you declare that in the for block where it is used instead ? > > > > > > > > > > > > > + char *of_display_format = "of-display.%d"; > > > > > > > > > > > > Should be const ? > > > > > > > > > > That should be static const of_display_format[] = then > > > > > > > > Why? It sounds completely fine to have a const pointer to a string > > > > constatnt. > > > > > > Generally speaking: > > > > > > 'static' because your const pointer is then not a local variable, so it > > > takes pressure off the stack. For global variables, you don't want them to > > > show up in any linker symbol tables. > > > > This sounds a lot like an exemplar case of premature optimization. > > A simplistic compiler might do exactly what you say, and allocate a slot > > for the variable on the stack the moment the function is entered. > > > > However, in real compilers there is no stack pressure from having a > > local variable: > > - the compiler can put the variable into a register > > - it can completely omit the variable before and after it's actually > > used which is that specific function call > > > > > The string "of-display.%d" is stored as an array in the ELF data section. > > > And your char pointer is a reference to that array. For static pointers, > > > these indirections take CPU cycles to update when the loader has to relocate > > > > Provided that the char pointer ever exists in the compiled code. Its > > address is not taken so it does not need to. > > > > > sections. If you declare of_display_format[] directly as array, you avoid > > > the reference and work directly with the array. > > > > > > Of course, this is a kernel module and the string is self-contained within > > > the function. So the compiler can probably detect that and optimize the code > > > to be like the 'static const []' version. It's still good to follow best > > > practices, as someone might copy from this function. > > > > If it could not detect it there would be a lot of trouble all around. > > The issues definitely exist in userspace code. Kernel modules are simpler, > so compiler optimization is easier. > > But I'm not really trying to make a technical argument. My point here is > that someone might read your code and duplicate the pattern. That's not > unreasonable: it's core Linux code, so it can be assumed to be good (or at > least not bad). But your current code teaches the reader a bad practices, > which should be avoided. It is better to do the correct thing, even if it > makes no difference to the compiled code. The point I am trying to get across is that besides the original objection about missing 'const' this code is not bad. Loading a string constant address into a local variable and passing it as function call argument is perfectly fine. If you get any advantage by the alternate convoluted construct it's more likely than anything else a bug in the compiler you are using. It may be necessary to work around such bugs in performance-critical code but not in driver probing code that runs exactly once during boot. Thanks Michal
On Thu, Jan 19, 2023 at 11:34:46AM +0100, Michal Suchánek wrote: > Hello, > > On Thu, Jan 19, 2023 at 10:24:07AM +0000, Christophe Leroy wrote: > > > > > > Le 19/01/2023 à 10:53, Michal Suchanek a écrit : > > > The commit 2d681d6a23a1 ("of: Make of framebuffer devices unique") > > > breaks build because of wrong argument to snprintf. That certainly > > > avoids the runtime error but is not the intended outcome. > > > > > > Also use standard device name format of-display.N for all created > > > devices. > > > > > > Fixes: 2d681d6a23a1 ("of: Make of framebuffer devices unique") > > > Signed-off-by: Michal Suchanek <msuchanek@suse.de> > > > --- > > > v2: Update the device name format > > > --- > > > drivers/of/platform.c | 12 ++++++++---- > > > 1 file changed, 8 insertions(+), 4 deletions(-) > > > > > > diff --git a/drivers/of/platform.c b/drivers/of/platform.c > > > index f2a5d679a324..8c1b1de22036 100644 > > > --- a/drivers/of/platform.c > > > +++ b/drivers/of/platform.c > > > @@ -525,7 +525,9 @@ 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 = 1; > > > + int display_number = 0; > > > + char buf[14]; > > > > Can you declare that in the for block where it is used instead ? > > No, there are two for blocks. > > > > > > + char *of_display_format = "of-display.%d"; > > > > Should be const ? > > Yes, could be. > > > > > > int ret; > > > > > > /* Check if we have a MacOS display without a node spec */ > > > @@ -556,7 +558,10 @@ 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); > > > + ret = snprintf(buf, sizeof(buf), of_display_format, display_number++); > > > + if (ret >= sizeof(buf)) > > > + continue; > > > > > > Can you make buf big enough to avoid that ? > > It would be a bit fragile that way. > > The buffer would have to theoretically accomodate > "of-display.-9223372036854775808", and any change to the format requires > recalculating the length, by hand. > > Of course, the memory would run out way before allocating that many > devices so it's kind of pointless to try and accomodate all possible > device numbers. > > > > > And by the way could it be called something else than 'buf' ? > > > > See exemple here : > > https://elixir.bootlin.com/linux/v6.1/source/drivers/fsi/fsi-occ.c#L690 > > Yes, that is quite possible. Nonetheless, just like 'ret' generic > variable names also work. And in fact judicious use of short generic variable names is more readeable than naming all variables foobar_* as far as I am concerned. Of course, YMMV. Thanks Michal
On Thu, Jan 19, 2023 at 3:53 AM Michal Suchanek <msuchanek@suse.de> wrote: > > The commit 2d681d6a23a1 ("of: Make of framebuffer devices unique") > breaks build because of wrong argument to snprintf. That certainly > avoids the runtime error but is not the intended outcome. > > Also use standard device name format of-display.N for all created > devices. > > Fixes: 2d681d6a23a1 ("of: Make of framebuffer devices unique") > Signed-off-by: Michal Suchanek <msuchanek@suse.de> > --- > v2: Update the device name format > --- > drivers/of/platform.c | 12 ++++++++---- > 1 file changed, 8 insertions(+), 4 deletions(-) > > diff --git a/drivers/of/platform.c b/drivers/of/platform.c > index f2a5d679a324..8c1b1de22036 100644 > --- a/drivers/of/platform.c > +++ b/drivers/of/platform.c > @@ -525,7 +525,9 @@ 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 = 1; > + int display_number = 0; > + char buf[14]; > + char *of_display_format = "of-display.%d"; static const as suggested and can we just move on please... > int ret; > > /* Check if we have a MacOS display without a node spec */ > @@ -556,7 +558,10 @@ 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); > + ret = snprintf(buf, sizeof(buf), of_display_format, display_number++); The boot display is always "of-display.0". Just use the fixed string here. Then we can get rid of the whole debate around static const. > + if (ret >= sizeof(buf)) > + continue; This only happens if display_number becomes too big. Why continue on? The next iteration will fail too. > + dev = of_platform_device_create(node, buf, NULL); > if (WARN_ON(!dev)) > return -ENOMEM; > boot_display = node; > @@ -564,10 +569,9 @@ static int __init of_platform_default_populate_init(void) > } > > for_each_node_by_type(node, "display") { > - char *buf[14]; > if (!of_get_property(node, "linux,opened", NULL) || node == boot_display) > continue; > - ret = snprintf(buf, "of-display-%d", display_number++); > + ret = snprintf(buf, sizeof(buf), of_display_format, display_number++); > if (ret >= sizeof(buf)) > continue; Here too in the original change. > of_platform_device_create(node, buf, NULL); > -- > 2.35.3 >
Hello, On Fri, Jan 20, 2023 at 11:23:39AM -0600, Rob Herring wrote: > On Thu, Jan 19, 2023 at 3:53 AM Michal Suchanek <msuchanek@suse.de> wrote: > > > > The commit 2d681d6a23a1 ("of: Make of framebuffer devices unique") > > breaks build because of wrong argument to snprintf. That certainly > > avoids the runtime error but is not the intended outcome. > > > > Also use standard device name format of-display.N for all created > > devices. > > > > Fixes: 2d681d6a23a1 ("of: Make of framebuffer devices unique") > > Signed-off-by: Michal Suchanek <msuchanek@suse.de> > > --- > > v2: Update the device name format > > --- > > drivers/of/platform.c | 12 ++++++++---- > > 1 file changed, 8 insertions(+), 4 deletions(-) > > > > diff --git a/drivers/of/platform.c b/drivers/of/platform.c > > index f2a5d679a324..8c1b1de22036 100644 > > --- a/drivers/of/platform.c > > +++ b/drivers/of/platform.c > > @@ -525,7 +525,9 @@ 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 = 1; > > + int display_number = 0; > > + char buf[14]; > > + char *of_display_format = "of-display.%d"; > > static const as suggested and can we just move on please... Only const, static could be dodgy > > int ret; > > > > /* Check if we have a MacOS display without a node spec */ > > @@ -556,7 +558,10 @@ 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); > > + ret = snprintf(buf, sizeof(buf), of_display_format, display_number++); > > The boot display is always "of-display.0". Just use the fixed string > here. Then we can get rid of the whole debate around static const. I prefer to use the same format string when the names should be consistent. Also it would resurrect the starting from 1 debate. But if you really want to have two strings I do not care all that much. > > > + if (ret >= sizeof(buf)) > > + continue; > > This only happens if display_number becomes too big. Why continue on? > The next iteration will fail too. Yes, there is no need to continue with the loop. Thanks Michal > > > + dev = of_platform_device_create(node, buf, NULL); > > if (WARN_ON(!dev)) > > return -ENOMEM; > > boot_display = node; > > @@ -564,10 +569,9 @@ static int __init of_platform_default_populate_init(void) > > } > > > > for_each_node_by_type(node, "display") { > > - char *buf[14]; > > if (!of_get_property(node, "linux,opened", NULL) || node == boot_display) > > continue; > > - ret = snprintf(buf, "of-display-%d", display_number++); > > + ret = snprintf(buf, sizeof(buf), of_display_format, display_number++); > > if (ret >= sizeof(buf)) > > continue; > > Here too in the original change. > > > of_platform_device_create(node, buf, NULL); > > -- > > 2.35.3 > >
diff --git a/drivers/of/platform.c b/drivers/of/platform.c index f2a5d679a324..8c1b1de22036 100644 --- a/drivers/of/platform.c +++ b/drivers/of/platform.c @@ -525,7 +525,9 @@ 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 = 1; + int display_number = 0; + char buf[14]; + char *of_display_format = "of-display.%d"; int ret; /* Check if we have a MacOS display without a node spec */ @@ -556,7 +558,10 @@ 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); + ret = snprintf(buf, sizeof(buf), of_display_format, display_number++); + if (ret >= sizeof(buf)) + continue; + dev = of_platform_device_create(node, buf, NULL); if (WARN_ON(!dev)) return -ENOMEM; boot_display = node; @@ -564,10 +569,9 @@ static int __init of_platform_default_populate_init(void) } for_each_node_by_type(node, "display") { - char *buf[14]; if (!of_get_property(node, "linux,opened", NULL) || node == boot_display) continue; - ret = snprintf(buf, "of-display-%d", display_number++); + ret = snprintf(buf, sizeof(buf), of_display_format, display_number++); if (ret >= sizeof(buf)) continue; of_platform_device_create(node, buf, NULL);