Re: [PATCH] serial: 8250_platform: Fix structure initialization warning
From: Sunil V L
Date: Wed Aug 07 2024 - 01:55:24 EST
Hi Stephen,
On Wed, Aug 07, 2024 at 03:13:52PM +1000, Stephen Rothwell wrote:
> Hi Sunil,
>
> On Wed, 7 Aug 2024 09:52:10 +0530 Sunil V L <sunilvl@xxxxxxxxxxxxxxxx> wrote:
> >
>
> > diff --git a/drivers/tty/serial/8250/8250_platform.c b/drivers/tty/serial/8250/8250_platform.c
> > index bdfb16bed4f2..d8c3c169a620 100644
> > --- a/drivers/tty/serial/8250/8250_platform.c
> > +++ b/drivers/tty/serial/8250/8250_platform.c
> > @@ -108,11 +108,12 @@ void __init serial8250_isa_init_ports(void)
> > static int serial8250_platform_probe(struct platform_device *pdev)
> > {
> > struct device *dev = &pdev->dev;
> > - struct uart_8250_port uart = { 0 };
> > + struct uart_8250_port uart;
>
> Does just using "{ }" as an initialiser work without warning?
>
I tried that and at least on this architecture/compiler combination, the
warning is gone. However, I was not sure about it since gcc man page
indicates such initialization is valid for C++.
Quoting gcc manpage:
-Wmissing-field-initializers
In C this option does not warn about the universal zero initializer ‘{ 0 }’:
struct s { int f, g, h; };
struct s x = { 0 };
Likewise, in C++ this option does not warn about the empty { } initializer, for
example:
struct s { int f, g, h; };
s x = { };
So, I thought doing memset is probably safer which should work across
architectures/compiler combinations.
Thanks,
Sunil