linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] geneve: Add missing braces in addr6 initializer
@ 2018-11-12 22:12 Nathan Chancellor
  2018-11-12 22:19 ` Stefano Brivio
                   ` (3 more replies)
  0 siblings, 4 replies; 15+ messages in thread
From: Nathan Chancellor @ 2018-11-12 22:12 UTC (permalink / raw)
  To: David S. Miller
  Cc: Stefano Brivio, Sabrina Dubroca, netdev, linux-kernel, Nathan Chancellor

Clang warns:

drivers/net/geneve.c:428:29: error: suggest braces around initialization
of subobject [-Werror,-Wmissing-braces]
                struct in6_addr addr6 = { 0 };
                                          ^
                                          {}

Fixes: a07966447f39 ("geneve: ICMP error lookup handler")
Signed-off-by: Nathan Chancellor <natechancellor@gmail.com>
---
 drivers/net/geneve.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/geneve.c b/drivers/net/geneve.c
index 7c53e06b31c3..224d8b0bb5de 100644
--- a/drivers/net/geneve.c
+++ b/drivers/net/geneve.c
@@ -425,7 +425,7 @@ static int geneve_udp_encap_err_lookup(struct sock *sk, struct sk_buff *skb)
 #if IS_ENABLED(CONFIG_IPV6)
 	if (geneve_get_sk_family(gs) == AF_INET6) {
 		struct ipv6hdr *ip6h = ipv6_hdr(skb);
-		struct in6_addr addr6 = { 0 };
+		struct in6_addr addr6 = { { 0 } };
 
 		if (!gs->collect_md) {
 			vni = geneve_hdr(skb)->vni;
-- 
2.19.1


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* Re: [PATCH] geneve: Add missing braces in addr6 initializer
  2018-11-12 22:12 [PATCH] geneve: Add missing braces in addr6 initializer Nathan Chancellor
@ 2018-11-12 22:19 ` Stefano Brivio
  2018-11-12 22:20   ` Nathan Chancellor
  2018-11-12 22:36 ` Joe Perches
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 15+ messages in thread
From: Stefano Brivio @ 2018-11-12 22:19 UTC (permalink / raw)
  To: Nathan Chancellor; +Cc: David S. Miller, Sabrina Dubroca, netdev, linux-kernel

On Mon, 12 Nov 2018 15:12:48 -0700
Nathan Chancellor <natechancellor@gmail.com> wrote:

> Clang warns:
> 
> drivers/net/geneve.c:428:29: error: suggest braces around initialization
> of subobject [-Werror,-Wmissing-braces]
>                 struct in6_addr addr6 = { 0 };
>                                           ^
>                                           {}
> 
> Fixes: a07966447f39 ("geneve: ICMP error lookup handler")
> Signed-off-by: Nathan Chancellor <natechancellor@gmail.com>

Thanks for spotting this. By the way, I guess you should indicate in
the subject when patches are meant for net-next.

Reviewed-by: Stefano Brivio <sbrivio@redhat.com>

-- 
Stefano

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH] geneve: Add missing braces in addr6 initializer
  2018-11-12 22:19 ` Stefano Brivio
@ 2018-11-12 22:20   ` Nathan Chancellor
  0 siblings, 0 replies; 15+ messages in thread
From: Nathan Chancellor @ 2018-11-12 22:20 UTC (permalink / raw)
  To: Stefano Brivio; +Cc: David S. Miller, Sabrina Dubroca, netdev, linux-kernel

On Mon, Nov 12, 2018 at 11:19:17PM +0100, Stefano Brivio wrote:
> On Mon, 12 Nov 2018 15:12:48 -0700
> Nathan Chancellor <natechancellor@gmail.com> wrote:
> 
> > Clang warns:
> > 
> > drivers/net/geneve.c:428:29: error: suggest braces around initialization
> > of subobject [-Werror,-Wmissing-braces]
> >                 struct in6_addr addr6 = { 0 };
> >                                           ^
> >                                           {}
> > 
> > Fixes: a07966447f39 ("geneve: ICMP error lookup handler")
> > Signed-off-by: Nathan Chancellor <natechancellor@gmail.com>
> 
> Thanks for spotting this. By the way, I guess you should indicate in
> the subject when patches are meant for net-next.
> 

Sure, I'll be better about that in the future.

> Reviewed-by: Stefano Brivio <sbrivio@redhat.com>
> 

Thank you for the review!
Nathan

> -- 
> Stefano

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH] geneve: Add missing braces in addr6 initializer
  2018-11-12 22:12 [PATCH] geneve: Add missing braces in addr6 initializer Nathan Chancellor
  2018-11-12 22:19 ` Stefano Brivio
@ 2018-11-12 22:36 ` Joe Perches
  2018-11-13  6:11 ` [PATCH net-next v2] geneve: Use empty braces for " Nathan Chancellor
  2018-11-15 19:35 ` [PATCH] geneve: Add missing braces in addr6 initializer David Miller
  3 siblings, 0 replies; 15+ messages in thread
From: Joe Perches @ 2018-11-12 22:36 UTC (permalink / raw)
  To: Nathan Chancellor, David S. Miller
  Cc: Stefano Brivio, Sabrina Dubroca, netdev, linux-kernel

On Mon, 2018-11-12 at 15:12 -0700, Nathan Chancellor wrote:
> Clang warns:
> 
> drivers/net/geneve.c:428:29: error: suggest braces around initialization
> of subobject [-Werror,-Wmissing-braces]
>                 struct in6_addr addr6 = { 0 };
>                                           ^
>                                           {}

Perhaps just remove the 0.

> diff --git a/drivers/net/geneve.c b/drivers/net/geneve.c
[]
> @@ -425,7 +425,7 @@ static int geneve_udp_encap_err_lookup(struct sock *sk, struct sk_buff *skb)
>  #if IS_ENABLED(CONFIG_IPV6)
>  	if (geneve_get_sk_family(gs) == AF_INET6) {
>  		struct ipv6hdr *ip6h = ipv6_hdr(skb);
> -		struct in6_addr addr6 = { 0 };
> +		struct in6_addr addr6 = { { 0 } };
>  
>  		if (!gs->collect_md) {
>  			vni = geneve_hdr(skb)->vni;


^ permalink raw reply	[flat|nested] 15+ messages in thread

* [PATCH net-next v2] geneve: Use empty braces for addr6 initializer
  2018-11-12 22:12 [PATCH] geneve: Add missing braces in addr6 initializer Nathan Chancellor
  2018-11-12 22:19 ` Stefano Brivio
  2018-11-12 22:36 ` Joe Perches
@ 2018-11-13  6:11 ` Nathan Chancellor
  2018-11-13  9:02   ` Stefano Brivio
                     ` (2 more replies)
  2018-11-15 19:35 ` [PATCH] geneve: Add missing braces in addr6 initializer David Miller
  3 siblings, 3 replies; 15+ messages in thread
From: Nathan Chancellor @ 2018-11-13  6:11 UTC (permalink / raw)
  To: David S. Miller
  Cc: Stefano Brivio, Sabrina Dubroca, netdev, linux-kernel,
	Joe Perches, Nathan Chancellor

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.

Fixes: a07966447f39 ("geneve: ICMP error lookup handler")
Suggested-by: Joe Perches <joe@perches.com>
Signed-off-by: Nathan Chancellor <natechancellor@gmail.com>
---

v1 -> v2:

* Just remove the zero instead of adding more braces as it seems to
  match the rest of the kernel (as suggested by Joe Perches).

 drivers/net/geneve.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/geneve.c b/drivers/net/geneve.c
index 7c53e06b31c3..f09e58b7b01e 100644
--- a/drivers/net/geneve.c
+++ b/drivers/net/geneve.c
@@ -425,7 +425,7 @@ static int geneve_udp_encap_err_lookup(struct sock *sk, struct sk_buff *skb)
 #if IS_ENABLED(CONFIG_IPV6)
 	if (geneve_get_sk_family(gs) == AF_INET6) {
 		struct ipv6hdr *ip6h = ipv6_hdr(skb);
-		struct in6_addr addr6 = { 0 };
+		struct in6_addr addr6 = { };
 
 		if (!gs->collect_md) {
 			vni = geneve_hdr(skb)->vni;
-- 
2.19.1


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* Re: [PATCH net-next v2] geneve: Use empty braces for addr6 initializer
  2018-11-13  6:11 ` [PATCH net-next v2] geneve: Use empty braces for " Nathan Chancellor
@ 2018-11-13  9:02   ` Stefano Brivio
  2018-11-16 14:04   ` Stefano Brivio
  2018-11-17  1:36   ` [PATCH net-next v3] geneve: Initialize addr6 with memset Nathan Chancellor
  2 siblings, 0 replies; 15+ messages in thread
From: Stefano Brivio @ 2018-11-13  9:02 UTC (permalink / raw)
  To: Nathan Chancellor
  Cc: David S. Miller, Sabrina Dubroca, netdev, linux-kernel, Joe Perches

On Mon, 12 Nov 2018 23:11:47 -0700
Nathan Chancellor <natechancellor@gmail.com> 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.
> 
> Fixes: a07966447f39 ("geneve: ICMP error lookup handler")
> Suggested-by: Joe Perches <joe@perches.com>
> Signed-off-by: Nathan Chancellor <natechancellor@gmail.com>

Also,

Reviewed-by: Stefano Brivio <sbrivio@redhat.com>

-- 
Stefano

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH] geneve: Add missing braces in addr6 initializer
  2018-11-12 22:12 [PATCH] geneve: Add missing braces in addr6 initializer Nathan Chancellor
                   ` (2 preceding siblings ...)
  2018-11-13  6:11 ` [PATCH net-next v2] geneve: Use empty braces for " Nathan Chancellor
@ 2018-11-15 19:35 ` David Miller
  2018-11-15 19:38   ` Nathan Chancellor
  3 siblings, 1 reply; 15+ messages in thread
From: David Miller @ 2018-11-15 19:35 UTC (permalink / raw)
  To: natechancellor; +Cc: sbrivio, sd, netdev, linux-kernel

From: Nathan Chancellor <natechancellor@gmail.com>
Date: Mon, 12 Nov 2018 15:12:48 -0700

> Clang warns:
> 
> drivers/net/geneve.c:428:29: error: suggest braces around initialization
> of subobject [-Werror,-Wmissing-braces]
>                 struct in6_addr addr6 = { 0 };
>                                           ^
>                                           {}
> 
> Fixes: a07966447f39 ("geneve: ICMP error lookup handler")
> Signed-off-by: Nathan Chancellor <natechancellor@gmail.com>

And this makes GCC warn.

drivers/net/geneve.c: In function ‘geneve_udp_encap_err_lookup’:
drivers/net/geneve.c:428:27: warning: missing braces around initializer [-Wmissing-braces]
   struct in6_addr addr6 = { { 0 } };
                           ^
                               { }

(╯°□°)╯︵ ┻━┻

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH] geneve: Add missing braces in addr6 initializer
  2018-11-15 19:35 ` [PATCH] geneve: Add missing braces in addr6 initializer David Miller
@ 2018-11-15 19:38   ` Nathan Chancellor
  0 siblings, 0 replies; 15+ messages in thread
From: Nathan Chancellor @ 2018-11-15 19:38 UTC (permalink / raw)
  To: David Miller; +Cc: sbrivio, sd, netdev, linux-kernel

On Thu, Nov 15, 2018 at 11:35:01AM -0800, David Miller wrote:
> From: Nathan Chancellor <natechancellor@gmail.com>
> Date: Mon, 12 Nov 2018 15:12:48 -0700
> 
> > Clang warns:
> > 
> > drivers/net/geneve.c:428:29: error: suggest braces around initialization
> > of subobject [-Werror,-Wmissing-braces]
> >                 struct in6_addr addr6 = { 0 };
> >                                           ^
> >                                           {}
> > 
> > Fixes: a07966447f39 ("geneve: ICMP error lookup handler")
> > Signed-off-by: Nathan Chancellor <natechancellor@gmail.com>
> 
> And this makes GCC warn.
> 
> drivers/net/geneve.c: In function ‘geneve_udp_encap_err_lookup’:
> drivers/net/geneve.c:428:27: warning: missing braces around initializer [-Wmissing-braces]
>    struct in6_addr addr6 = { { 0 } };
>                            ^
>                                { }
> 
> (╯°□°)╯︵ ┻━┻

Yes, sorry, I thought I test built before sending it but apparently not
:( v2 should be sitting in your inbox as a reply to this one unless I
screwed that up too...

Nathan

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH net-next v2] geneve: Use empty braces for addr6 initializer
  2018-11-13  6:11 ` [PATCH net-next v2] geneve: Use empty braces for " Nathan Chancellor
  2018-11-13  9:02   ` Stefano Brivio
@ 2018-11-16 14:04   ` Stefano Brivio
  2018-11-16 15:37     ` Nathan Chancellor
  2018-11-16 20:35     ` David Miller
  2018-11-17  1:36   ` [PATCH net-next v3] geneve: Initialize addr6 with memset Nathan Chancellor
  2 siblings, 2 replies; 15+ messages in thread
From: Stefano Brivio @ 2018-11-16 14:04 UTC (permalink / raw)
  To: Nathan Chancellor, Joe Perches
  Cc: David S. Miller, Sabrina Dubroca, netdev, linux-kernel

On Mon, 12 Nov 2018 23:11:47 -0700
Nathan Chancellor <natechancellor@gmail.com> 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

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH net-next v2] geneve: Use empty braces for addr6 initializer
  2018-11-16 14:04   ` Stefano Brivio
@ 2018-11-16 15:37     ` Nathan Chancellor
  2018-11-17  2:33       ` Joe Perches
  2018-11-16 20:35     ` David Miller
  1 sibling, 1 reply; 15+ messages in thread
From: Nathan Chancellor @ 2018-11-16 15:37 UTC (permalink / raw)
  To: Stefano Brivio
  Cc: Joe Perches, David S. Miller, Sabrina Dubroca, netdev, linux-kernel

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@gmail.com> 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

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH net-next v2] geneve: Use empty braces for addr6 initializer
  2018-11-16 14:04   ` Stefano Brivio
  2018-11-16 15:37     ` Nathan Chancellor
@ 2018-11-16 20:35     ` David Miller
  1 sibling, 0 replies; 15+ messages in thread
From: David Miller @ 2018-11-16 20:35 UTC (permalink / raw)
  To: sbrivio; +Cc: natechancellor, joe, sd, netdev, linux-kernel

From: Stefano Brivio <sbrivio@redhat.com>
Date: Fri, 16 Nov 2018 15:04:32 +0100

> Joe, suggestions?

Let's just memset() this thing already instead of fighting the
compiler(s).

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [PATCH net-next v3] geneve: Initialize addr6 with memset
  2018-11-13  6:11 ` [PATCH net-next v2] geneve: Use empty braces for " Nathan Chancellor
  2018-11-13  9:02   ` Stefano Brivio
  2018-11-16 14:04   ` Stefano Brivio
@ 2018-11-17  1:36   ` Nathan Chancellor
  2018-11-18  6:03     ` David Miller
  2 siblings, 1 reply; 15+ messages in thread
From: Nathan Chancellor @ 2018-11-17  1:36 UTC (permalink / raw)
  To: David S. Miller
  Cc: Stefano Brivio, Sabrina Dubroca, netdev, linux-kernel, Nathan Chancellor

Clang warns:

drivers/net/geneve.c:428:29: error: suggest braces around initialization
of subobject [-Werror,-Wmissing-braces]
                struct in6_addr addr6 = { 0 };
                                          ^
                                          {}

Rather than trying to appease the various compilers that support the
kernel, use memset, which is unambiguous.

Fixes: a07966447f39 ("geneve: ICMP error lookup handler")
Suggested-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Nathan Chancellor <natechancellor@gmail.com>
---

v1 -> v2:

* Just remove the zero instead of adding more braces as it seems to
  match the rest of the kernel (as suggested by Joe Perches).

v2 -> v3:

* Use memset as suggested by David Miller.

 drivers/net/geneve.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/net/geneve.c b/drivers/net/geneve.c
index 7c53e06b31c3..58bbba8582b0 100644
--- a/drivers/net/geneve.c
+++ b/drivers/net/geneve.c
@@ -425,7 +425,9 @@ static int geneve_udp_encap_err_lookup(struct sock *sk, struct sk_buff *skb)
 #if IS_ENABLED(CONFIG_IPV6)
 	if (geneve_get_sk_family(gs) == AF_INET6) {
 		struct ipv6hdr *ip6h = ipv6_hdr(skb);
-		struct in6_addr addr6 = { 0 };
+		struct in6_addr addr6;
+
+		memset(&addr6, 0, sizeof(struct in6_addr));
 
 		if (!gs->collect_md) {
 			vni = geneve_hdr(skb)->vni;
-- 
2.19.1


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* Re: [PATCH net-next v2] geneve: Use empty braces for addr6 initializer
  2018-11-16 15:37     ` Nathan Chancellor
@ 2018-11-17  2:33       ` Joe Perches
  2018-11-17 11:31         ` Stefano Brivio
  0 siblings, 1 reply; 15+ messages in thread
From: Joe Perches @ 2018-11-17  2:33 UTC (permalink / raw)
  To: Nathan Chancellor, Stefano Brivio
  Cc: David S. Miller, Sabrina Dubroca, netdev, linux-kernel

On Fri, 2018-11-16 at 08:37 -0700, Nathan Chancellor wrote:
> 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@gmail.com> 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.
[]
> > So { { { 0 } } } seems to be the safest option. We could go with static
> > but it looks even uglier to me.
> > 
> > Joe, suggestions?

If this is really an issue, I don't know why the other uses
haven't been reported.  Perhaps change the rest of them too?

$ git grep -P "struct\s+in6_addr\s+\w+\s*=\s*{\s*}"
include/net/ip6_fib.h:          struct in6_addr in6_zero = {};
include/trace/events/fib6.h:                    struct in6_addr in6_zero = {};
net/6lowpan/iphc.c:     struct in6_addr network_pfx = {};
net/6lowpan/iphc.c:     struct in6_addr tmp = {};
net/6lowpan/iphc.c:     struct in6_addr tmp = {};
net/6lowpan/iphc.c:     struct in6_addr tmp = {};
net/6lowpan/iphc.c:     struct in6_addr tmp = {};




^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH net-next v2] geneve: Use empty braces for addr6 initializer
  2018-11-17  2:33       ` Joe Perches
@ 2018-11-17 11:31         ` Stefano Brivio
  0 siblings, 0 replies; 15+ messages in thread
From: Stefano Brivio @ 2018-11-17 11:31 UTC (permalink / raw)
  To: Joe Perches, Nathan Chancellor, David S. Miller
  Cc: Sabrina Dubroca, netdev, linux-kernel

On Fri, 16 Nov 2018 18:33:40 -0800
Joe Perches <joe@perches.com> wrote:

> If this is really an issue, I don't know why the other uses
> haven't been reported.

It causes warnings with some older gcc versions and clang, I don't see
it as an issue, but others might.

> Perhaps change the rest of them too?

But then look, we already have a delicious strict C89 initialiser in
include/linux/in6.h, and we can do this:

 drivers/net/geneve.c        |    4 ++--
 include/net/ip6_fib.h       |    9 +++------
 include/trace/events/fib6.h |    4 +---
 net/6lowpan/iphc.c          |   12 ++++++------
 4 files changed, 12 insertions(+), 17 deletions(-)

diff --git a/drivers/net/geneve.c b/drivers/net/geneve.c
index 7c53e06b31c3..96588adc294c 100644
--- a/drivers/net/geneve.c
+++ b/drivers/net/geneve.c
@@ -191,7 +191,7 @@ static struct geneve_dev *geneve_lookup_skb(struct geneve_sock *gs,
                return geneve_lookup(gs, addr, vni);
 #if IS_ENABLED(CONFIG_IPV6)
        } else if (geneve_get_sk_family(gs) == AF_INET6) {
-               static struct in6_addr zero_addr6;
+               struct in6_addr zero_addr6 = IN6ADDR_ANY_INIT;
                struct ipv6hdr *ip6h;
                struct in6_addr addr6;
 
@@ -424,8 +424,8 @@ static int geneve_udp_encap_err_lookup(struct sock *sk, struct sk_buff *skb)
 
 #if IS_ENABLED(CONFIG_IPV6)
        if (geneve_get_sk_family(gs) == AF_INET6) {
+               struct in6_addr addr6 = IN6ADDR_ANY_INIT;
                struct ipv6hdr *ip6h = ipv6_hdr(skb);
-               struct in6_addr addr6 = { 0 };
 
                if (!gs->collect_md) {
                        vni = geneve_hdr(skb)->vni;
diff --git a/include/net/ip6_fib.h b/include/net/ip6_fib.h
index 84097010237c..24543caf5a9f 100644
--- a/include/net/ip6_fib.h
+++ b/include/net/ip6_fib.h
@@ -427,13 +427,10 @@ void rt6_get_prefsrc(const struct rt6_info *rt, struct in6_addr *addr)
        rcu_read_lock();
 
        from = rcu_dereference(rt->from);
-       if (from) {
+       if (from)
                *addr = from->fib6_prefsrc.addr;
-       } else {
-               struct in6_addr in6_zero = {};
-
-               *addr = in6_zero;
-       }
+       else
+               *addr = in6addr_any;
 
        rcu_read_unlock();
 }
diff --git a/include/trace/events/fib6.h b/include/trace/events/fib6.h
index b088b54d699c..6496ca1594ac 100644
--- a/include/trace/events/fib6.h
+++ b/include/trace/events/fib6.h
@@ -68,10 +68,8 @@ TRACE_EVENT(fib6_table_lookup,
                        __assign_str(name, "-");
                }
                if (f6i == net->ipv6.fib6_null_entry) {
-                       struct in6_addr in6_zero = {};
-
                        in6 = (struct in6_addr *)__entry->gw;
-                       *in6 = in6_zero;
+                       *in6 = in6addr_any;
 
                } else if (f6i) {
                        in6 = (struct in6_addr *)__entry->gw;
diff --git a/net/6lowpan/iphc.c b/net/6lowpan/iphc.c
index 52fad5dad9f7..f0e0bac91e71 100644
--- a/net/6lowpan/iphc.c
+++ b/net/6lowpan/iphc.c
@@ -246,8 +246,8 @@ lowpan_iphc_ctx_get_by_mcast_addr(const struct net_device *dev,
                                  const struct in6_addr *addr)
 {
        struct lowpan_iphc_ctx *table = lowpan_dev(dev)->ctx.table;
+       struct in6_addr addr_mcast, network_pfx = IN6ADDR_ANY_INIT;
        struct lowpan_iphc_ctx *ret = NULL;
-       struct in6_addr addr_mcast, network_pfx = {};
        int i;
 
        /* init mcast address with  */
@@ -481,7 +481,7 @@ static int lowpan_uncompress_multicast_ctx_daddr(struct sk_buff *skb,
                                                 struct in6_addr *ipaddr,
                                                 u8 address_mode)
 {
-       struct in6_addr network_pfx = {};
+       struct in6_addr network_pfx = IN6ADDR_ANY_INIT;
        bool fail;
 
        ipaddr->s6_addr[0] = 0xFF;
@@ -794,8 +794,8 @@ lowpan_iphc_compress_ctx_802154_lladdr(const struct in6_addr *ipaddr,
 {
        const struct ieee802154_addr *addr = lladdr;
        unsigned char extended_addr[EUI64_ADDR_LEN];
+       struct in6_addr tmp = IN6ADDR_ANY_INIT;
        bool lladdr_compress = false;
-       struct in6_addr tmp = {};
 
        switch (addr->mode) {
        case IEEE802154_ADDR_LONG:
@@ -833,7 +833,7 @@ static bool lowpan_iphc_addr_equal(const struct net_device *dev,
                                   const struct in6_addr *ipaddr,
                                   const void *lladdr)
 {
-       struct in6_addr tmp = {};
+       struct in6_addr tmp = IN6ADDR_ANY_INIT;
 
        lowpan_iphc_uncompress_lladdr(dev, &tmp, lladdr);
 
@@ -848,7 +848,7 @@ static u8 lowpan_compress_ctx_addr(u8 **hc_ptr, const struct net_device *dev,
                                   const struct lowpan_iphc_ctx *ctx,
                                   const unsigned char *lladdr, bool sam)
 {
-       struct in6_addr tmp = {};
+       struct in6_addr tmp = IN6ADDR_ANY_INIT;
        u8 dam;
 
        switch (lowpan_dev(dev)->lltype) {
@@ -907,8 +907,8 @@ lowpan_iphc_compress_802154_lladdr(const struct in6_addr *ipaddr,
 {
        const struct ieee802154_addr *addr = lladdr;
        unsigned char extended_addr[EUI64_ADDR_LEN];
+       struct in6_addr tmp = IN6ADDR_ANY_INIT;
        bool lladdr_compress = false;
-       struct in6_addr tmp = {};
 
        switch (addr->mode) {
        case IEEE802154_ADDR_LONG:

-- 
Stefano

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* Re: [PATCH net-next v3] geneve: Initialize addr6 with memset
  2018-11-17  1:36   ` [PATCH net-next v3] geneve: Initialize addr6 with memset Nathan Chancellor
@ 2018-11-18  6:03     ` David Miller
  0 siblings, 0 replies; 15+ messages in thread
From: David Miller @ 2018-11-18  6:03 UTC (permalink / raw)
  To: natechancellor; +Cc: sbrivio, sd, netdev, linux-kernel

From: Nathan Chancellor <natechancellor@gmail.com>
Date: Fri, 16 Nov 2018 18:36:27 -0700

> Clang warns:
> 
> drivers/net/geneve.c:428:29: error: suggest braces around initialization
> of subobject [-Werror,-Wmissing-braces]
>                 struct in6_addr addr6 = { 0 };
>                                           ^
>                                           {}
> 
> Rather than trying to appease the various compilers that support the
> kernel, use memset, which is unambiguous.
> 
> Fixes: a07966447f39 ("geneve: ICMP error lookup handler")
> Suggested-by: David S. Miller <davem@davemloft.net>
> Signed-off-by: Nathan Chancellor <natechancellor@gmail.com>

Applied.

^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2018-11-18  6:03 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-11-12 22:12 [PATCH] geneve: Add missing braces in addr6 initializer Nathan Chancellor
2018-11-12 22:19 ` Stefano Brivio
2018-11-12 22:20   ` Nathan Chancellor
2018-11-12 22:36 ` Joe Perches
2018-11-13  6:11 ` [PATCH net-next v2] geneve: Use empty braces for " Nathan Chancellor
2018-11-13  9:02   ` Stefano Brivio
2018-11-16 14:04   ` Stefano Brivio
2018-11-16 15:37     ` Nathan Chancellor
2018-11-17  2:33       ` Joe Perches
2018-11-17 11:31         ` Stefano Brivio
2018-11-16 20:35     ` David Miller
2018-11-17  1:36   ` [PATCH net-next v3] geneve: Initialize addr6 with memset Nathan Chancellor
2018-11-18  6:03     ` David Miller
2018-11-15 19:35 ` [PATCH] geneve: Add missing braces in addr6 initializer David Miller
2018-11-15 19:38   ` Nathan Chancellor

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).