[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20230120175253.GW16547@kitsune.suse.cz>
Date: Fri, 20 Jan 2023 18:52:53 +0100
From: Michal Suchánek <msuchanek@...e.de>
To: Rob Herring <robh+dt@...nel.org>
Cc: "Erhard F." <erhard_f@...lbox.org>,
Thomas Zimmermann <tzimmermann@...e.de>,
"open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE"
<devicetree@...r.kernel.org>, linuxppc-dev@...ts.ozlabs.org,
Javier Martinez Canillas <javierm@...hat.com>,
open list <linux-kernel@...r.kernel.org>,
Frank Rowand <frowand.list@...il.com>
Subject: Re: [PATCH v2] of: Fix of platform build on powerpc due to bad of
disaply code
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@...e.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@...e.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
> >
Powered by blists - more mailing lists