geneve: Add missing braces in addr6 initializer
Subsystems (5)
PATCH 1/1 geneve: Add missing braces in addr6 initializer
Clang warns:
drivers/net/geneve.c:428:29: error: suggest braces around initialization of subobject [-Werror,-Wmissing-braces]
struct in6_addr addr6 = { 0 };
^
{}--- drivers/net/geneve.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/geneve.c +1 -1
@@ -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;
Signature · 1 line
2.19.1
Quoted 10 lines · On Mon, 12 Nov 2018 15:12:48 -0700 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 <[email protected]>
Thanks for spotting this. By the way, I guess you should indicate in the subject when patches are meant for net-next.
Signature · 1 line
Stefano
Quoted 11 lines · Stefano Brivio
Quoted 8 lines · On Mon, 12 Nov 2018 15:12:48 -0700 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 }; ^ {}
Quoted 6 lines
Quoted 2 lines
Fixes a07966447f39 ("geneve: ICMP error lookup handler")Signed-off-by Nathan Chancellor <[email protected]>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.
Quoted 2 lines
Reviewed-by Stefano Brivio <[email protected]>
Thank you for the review!
Nathan
Quoted 2 lines
Signature · 1 line
Stefano
Quoted 7 lines · 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 }; ^ {}
Perhaps just remove the 0.
drivers/net/geneve.c
Quoted 1 line
drivers/net/geneve.c +0
-0
[]
Quoted 9 lines
drivers/net/geneve.c +1
-1@@ -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;
PATCH v2 1/1 geneve: Use empty braces for addr6 initializer
In reply to Nathan ChancellorClang 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.
---
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(-)
drivers/net/geneve.c +1 -1
@@ -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;
Signature · 1 line
2.19.1
Re: [PATCH net-next v2] geneve: Use empty braces for addr6 initializer
Quoted 8 lines · On Mon, 12 Nov 2018 23:11:47 -0700 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 }; ^ {}
Quoted 5 lines
Most initializations of structs in the kernel seem to use this format.
Fixes a07966447f39 ("geneve: ICMP error lookup handler")Suggested-by Joe Perches <[email protected]>Signed-off-by Nathan Chancellor <[email protected]>
Also,
Signature · 1 line
Stefano
Re: [PATCH net-next v2] geneve: Use empty braces for addr6 initializer
In reply to Nathan ChancellorQuoted 9 lines · On Mon, 12 Nov 2018 23:11:47 -0700 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.
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 -n1So { { { 0 } } } seems to be the safest option. We could go with static but it looks even uglier to me.
Joe, suggestions?
Signature · 1 line
Stefano
Re: [PATCH net-next v2] geneve: Use empty braces for addr6 initializer
Quoted 62 lines · Stefano Brivio
Quoted 9 lines · On Mon, 12 Nov 2018 23:11:47 -0700 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.
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
Quoted 7 lines
So { { { 0 } } } seems to be the safest option. We could go with static but it looks even uglier to me.
Joe, suggestions?
Signature · 1 line
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
Re: [PATCH net-next v2] geneve: Use empty braces for addr6 initializer
Quoted 6 lines · Nathan Chancellor
Quoted 5 lines · Stefano Brivio
Quoted 2 lines · On Mon, 12 Nov 2018 23:11:47 -0700 Nathan Chancellor…
Clang warns:
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
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.
[]
Quoted 4 lines
Quoted 4 lines
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 = {};Re: [PATCH net-next v2] geneve: Use empty braces for addr6 initializer
Quoted 2 lines · On Fri, 16 Nov 2018 18:33:40 -0800 Joe Perches <[email protected]> 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.
Quoted 1 line
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(-)
drivers/net/geneve.c +2 -2
@@ -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;
include/net/ip6_fib.h +3 -6
@@ -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 (); }
include/trace/events/fib6.h +1 -3
@@ -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;
net/6lowpan/iphc.c +6 -6
@@ -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 :
Signature · 1 line
Stefano
David Miller
maintainerRe: [PATCH net-next v2] geneve: Use empty braces for addr6 initializer
In reply to Stefano BrivioFrom: Stefano Brivio <[email protected]>
Date: Fri, 16 Nov 2018 15:04:32 +0100
Quoted 1 line
Joe, suggestions?
Let's just memset() this thing already instead of fighting the compiler(s).
PATCH v3 1/1 geneve: Initialize addr6 with memset
In reply to Nathan ChancellorClang 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.
---
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(-)
drivers/net/geneve.c +3 -1
@@ -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;
Signature · 1 line
2.19.1
Re: [PATCH net-next v3] geneve: Initialize addr6 with memset
From: Nathan Chancellor <[email protected]>
Date: Fri, 16 Nov 2018 18:36:27 -0700
Quoted 8 lines
Clang warns:
drivers/net/geneve.c:428:29: error: suggest braces around initialization of subobject [-Werror,-Wmissing-braces]struct in6_addr addr6 = { 0 }; ^ {}
Quoted 6 lines
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 <[email protected]>Signed-off-by Nathan Chancellor <[email protected]>
Applied.
David Miller
maintainerFrom: Nathan Chancellor <[email protected]>
Date: Mon, 12 Nov 2018 15:12:48 -0700
Quoted 10 lines
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 <[email protected]>
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 } };
^
{ }(╯°□°)╯︵ ┻━┻
Quoted 16 lines · David Miller
From: Nathan Chancellor <[email protected]>
Date: Mon, 12 Nov 2018 15:12:48 -0700Quoted 10 lines
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 <[email protected]>And this makes GCC warn.
Quoted 7 lines
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