serial: 8250_platform: Fix structure initialization warning
PATCH 1/1 serial: 8250_platform: Fix structure initialization warning
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')
--- drivers/tty/serial/8250/8250_platform.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/tty/serial/8250/8250_platform.c +2 -1
@@ -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;
Signature · 1 line
2.43.0
Hi Sunil,
drivers/tty/serial/8250/8250_platform.c void __init serial8250_isa_init_ports(void) · line 111
Quoted 12 lines · On Wed, 7 Aug 2024 09:52:10 +0530 Sunil V L <[email protected]> wrote:
drivers/tty/serial/8250/8250_platform.c +1
-1@@ -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?
Signature · 2 lines
Cheers, Stephen Rothwell
Hi Stephen,
Quoted 5 lines · Stephen Rothwell
Hi Sunil,
Quoted 1 line · On Wed, 7 Aug 2024 09:52:10 +0530 Sunil V L <[email protected]> wrote:
Quoted 13 lines
drivers/tty/serial/8250/8250_platform.c void __init serial8250_isa_init_ports(void) · line 111
Quoted 10 lines
drivers/tty/serial/8250/8250_platform.c +1
-1@@ -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
Greg Kroah-Hartman
maintainerQuoted 23 lines · Sunil V L
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 | structuart_8250_portuart = { 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 <[email protected]>Reported-by kernel test robot <[email protected]>Fixes d9e5a0ce2f16 ("serial: 8250_platform: Enable generic 16550A platform devices")Signed-off-by Sunil V L <[email protected]>--- drivers/tty/serial/8250/8250_platform.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/tty/serial/8250/8250_platform.c +0
-0
drivers/tty/serial/8250/8250_platform.c void __init serial8250_isa_init_ports(void) · line 111
Quoted 5 lines
drivers/tty/serial/8250/8250_platform.c +1
-1@@ -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