* [PATCH] serial: 8250_platform: Fix structure initialization warning
@ 2024-08-07 4:22 Sunil V L
2024-08-07 5:13 ` Stephen Rothwell
2024-08-07 11:02 ` Greg Kroah-Hartman
0 siblings, 2 replies; 4+ messages in thread
From: Sunil V L @ 2024-08-07 4:22 UTC (permalink / raw)
To: linux-kernel, linux-serial
Cc: Greg Kroah-Hartman, Jiri Slaby, Sunil V L, Stephen Rothwell,
kernel test robot
Use memset to initialize the uart structure instead of universal zero
initializer to fix the below warning.
drivers/tty/serial/8250/8250_platform.c: In function 'serial8250_platform_probe':
drivers/tty/serial/8250/8250_platform.c:111:40: warning: excess elements in struct initializer
111 | struct uart_8250_port uart = { 0 };
| ^
drivers/tty/serial/8250/8250_platform.c:111:40: note: (near initialization for 'uart.port.lock.<anonymous>.rlock.raw_lock')
Reported-by: Stephen Rothwell <sfr@canb.auug.org.au>
Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202407310023.h0JgJG1C-lkp@intel.com/
Fixes: d9e5a0ce2f16 ("serial: 8250_platform: Enable generic 16550A platform devices")
Signed-off-by: Sunil V L <sunilvl@ventanamicro.com>
---
drivers/tty/serial/8250/8250_platform.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
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;
struct resource *regs;
unsigned char iotype;
int ret, line;
+ memset(&uart, 0, sizeof(uart));
regs = platform_get_resource(pdev, IORESOURCE_IO, 0);
if (regs) {
uart.port.iobase = regs->start;
--
2.43.0
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH] serial: 8250_platform: Fix structure initialization warning
2024-08-07 4:22 [PATCH] serial: 8250_platform: Fix structure initialization warning Sunil V L
@ 2024-08-07 5:13 ` Stephen Rothwell
2024-08-07 5:55 ` Sunil V L
2024-08-07 11:02 ` Greg Kroah-Hartman
1 sibling, 1 reply; 4+ messages in thread
From: Stephen Rothwell @ 2024-08-07 5:13 UTC (permalink / raw)
To: Sunil V L
Cc: linux-kernel, linux-serial, Greg Kroah-Hartman, Jiri Slaby,
kernel test robot
[-- Attachment #1: Type: text/plain, Size: 694 bytes --]
Hi Sunil,
On Wed, 7 Aug 2024 09:52:10 +0530 Sunil V L <sunilvl@ventanamicro.com> 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?
--
Cheers,
Stephen Rothwell
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] serial: 8250_platform: Fix structure initialization warning
2024-08-07 5:13 ` Stephen Rothwell
@ 2024-08-07 5:55 ` Sunil V L
0 siblings, 0 replies; 4+ messages in thread
From: Sunil V L @ 2024-08-07 5:55 UTC (permalink / raw)
To: Stephen Rothwell
Cc: linux-kernel, linux-serial, Greg Kroah-Hartman, Jiri Slaby,
kernel test robot
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@ventanamicro.com> 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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] serial: 8250_platform: Fix structure initialization warning
2024-08-07 4:22 [PATCH] serial: 8250_platform: Fix structure initialization warning Sunil V L
2024-08-07 5:13 ` Stephen Rothwell
@ 2024-08-07 11:02 ` Greg Kroah-Hartman
1 sibling, 0 replies; 4+ messages in thread
From: Greg Kroah-Hartman @ 2024-08-07 11:02 UTC (permalink / raw)
To: Sunil V L
Cc: linux-kernel, linux-serial, Jiri Slaby, Stephen Rothwell,
kernel test robot
On Wed, Aug 07, 2024 at 09:52:10AM +0530, Sunil V L wrote:
> Use memset to initialize the uart structure instead of universal zero
> initializer to fix the below warning.
>
> drivers/tty/serial/8250/8250_platform.c: In function 'serial8250_platform_probe':
> drivers/tty/serial/8250/8250_platform.c:111:40: warning: excess elements in struct initializer
> 111 | struct uart_8250_port uart = { 0 };
> | ^
> drivers/tty/serial/8250/8250_platform.c:111:40: note: (near initialization for 'uart.port.lock.<anonymous>.rlock.raw_lock')
>
> Reported-by: Stephen Rothwell <sfr@canb.auug.org.au>
> Reported-by: kernel test robot <lkp@intel.com>
> Closes: https://lore.kernel.org/oe-kbuild-all/202407310023.h0JgJG1C-lkp@intel.com/
> Fixes: d9e5a0ce2f16 ("serial: 8250_platform: Enable generic 16550A platform devices")
> Signed-off-by: Sunil V L <sunilvl@ventanamicro.com>
> ---
> drivers/tty/serial/8250/8250_platform.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> 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;
{ } should be correct instead.
thanks,
greg k-h
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-08-07 11:02 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-07 4:22 [PATCH] serial: 8250_platform: Fix structure initialization warning Sunil V L
2024-08-07 5:13 ` Stephen Rothwell
2024-08-07 5:55 ` Sunil V L
2024-08-07 11:02 ` Greg Kroah-Hartman
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox