Re: [PATCH net-next v2] geneve: Use empty braces for addr6 initializer
From: Nathan Chancellor
Date: Fri Nov 16 2018 - 10:37:08 EST
On Fri, Nov 16, 2018 at 03:04:32PM +0100, Stefano Brivio wrote:
> On Mon, 12 Nov 2018 23:11:47 -0700
> Nathan Chancellor <natechancellor@xxxxxxxxx> wrote:
>
> > Clang warns:
> >
> > drivers/net/geneve.c:428:29: error: suggest braces around initialization
> > of subobject [-Werror,-Wmissing-braces]
> > struct in6_addr addr6 = { 0 };
> > ^
> > {}
> >
> > Most initializations of structs in the kernel seem to use this format.
>
> Actually, even with this, we get a warning with gcc 4.4 and 4.8. I tried a
> few compilers:
>
> $ gcc-4.4 --version | head -n1
> rhel-6.9-gcc (GCC) 4.4.7 20120313 (Red Hat 4.4.7-18)
> $ gcc-4.8 --version | head -n1
> rhel-7.5-gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-28)
> $ gcc-7.3 --version | head -n1
> gcc-7.3-gcc (GCC) 7.3.0
> $ gcc-8.2 --version | head -n1
> gcc (Debian 8.2.0-9) 8.2.0
> $ clang --version | head -n1
> clang version 6.0.1-9.2 (tags/RELEASE_601/final)
>
> $ cat init.c
> #include <linux/in6.h>
>
> int main()
> {
> struct in6_addr addr6 = INIT;
>
> return addr6.in6_u.u6_addr8[0];
> }
>
> $ gcc-4.4 -DINIT="{ }" -S -Wall -Wextra -o init init.c 2>&1 | grep warning | head -n1
> init.c:5: warning: missing initializer
> $ gcc-4.4 -DINIT="{ 0 }" -S -Wall -Wextra -o init init.c 2>&1 | grep warning | head -n1
> init.c:5: warning: missing braces around initializer
> $ gcc-4.4 -DINIT="{ { { 0 } } }" -S -Wall -Wextra -o init init.c 2>&1 | grep warning | head -n1
>
> $ gcc-4.8 -DINIT="{ }" -S -Wall -Wextra -o init init.c 2>&1 | grep warning | head -n1
> init.c:5:16: warning: missing initializer for field 'in6_u' of 'struct in6_addr' [-Wmissing-field-initializers]
> $ gcc-4.8 -DINIT="{ 0 }" -S -Wall -Wextra -o init init.c 2>&1 | grep warning | head -n1
> init.c:5:16: warning: missing braces around initializer [-Wmissing-braces]
> $ gcc-4.8 -DINIT="{ { { 0 } } }" -S -Wall -Wextra -o init init.c 2>&1 | grep warning | head -n1
>
> $ gcc-7.3 -DINIT="{ }" -S -Wall -Wextra -o init init.c 2>&1 | grep warning | head -n1
> $ gcc-7.3 -DINIT="{ 0 }" -S -Wall -Wextra -o init init.c 2>&1 | grep warning | head -n1
> $ gcc-7.3 -DINIT="{ { { 0 } } }" -S -Wall -Wextra -o init init.c 2>&1 | grep warning | head -n1
>
> $ gcc-8.2 -DINIT="{ }" -S -Wall -Wextra -o init init.c 2>&1 | grep warning | head -n1
> $ gcc-8.2 -DINIT="{ 0 }" -S -Wall -Wextra -o init init.c 2>&1 | grep warning | head -n1
> $ gcc-8.2 -DINIT="{ { { 0 } } }" -S -Wall -Wextra -o init init.c 2>&1 | grep warning | head -n1
>
> $ clang -DINIT="{ }" -S -Wall -Wextra -o init init.c 2>&1 | grep warning | head -n1
> $ clang -DINIT="{ 0 }" -S -Wall -Wextra -o init init.c 2>&1 | grep warning | head -n1
> init.c:5:33: warning: suggest braces around initialization of subobject [-Wmissing-braces]
> $ clang -DINIT="{ { { 0 } } }" -S -Wall -Wextra -o init init.c 2>&1 | grep warning | head -n1
>
> So { { { 0 } } } seems to be the safest option. We could go with static
> but it looks even uglier to me.
>
> Joe, suggestions?
>
> --
> Stefano
Yes, I used the wrong number of braces in the initial patch hence this
one. I'm fine with pushing that change as v3 if everyone agrees that is
fine.
Thanks for looking into this!
Nathan