* [PATCH] netfilter: Fix switch statement warnings with recent gcc.
@ 2015-04-08 3:05 David Miller
2015-04-08 16:46 ` Pablo Neira Ayuso
0 siblings, 1 reply; 3+ messages in thread
From: David Miller @ 2015-04-08 3:05 UTC (permalink / raw)
To: netfilter-devel; +Cc: pablo
More recent GCC warns about two kinds of switch statement uses:
1) Switching on an enumeration, but not having an explicit case
statement for all members of the enumeration. To show the
compiler this is intentional, we simply add a default case
with nothing more than a break statement.
2) Switching on a boolean value. I think this warning is dumb
but nevertheless you get it wholesale with -Wswitch.
This patch cures all such warnings in netfilter.
Signed-off-by: David S. Miller <davem@davemloft.net>
diff --git a/net/bridge/netfilter/nft_reject_bridge.c b/net/bridge/netfilter/nft_reject_bridge.c
index 54a2fdf..ae8141f 100644
--- a/net/bridge/netfilter/nft_reject_bridge.c
+++ b/net/bridge/netfilter/nft_reject_bridge.c
@@ -371,6 +371,8 @@ static int nft_reject_bridge_dump(struct sk_buff *skb,
if (nla_put_u8(skb, NFTA_REJECT_ICMP_CODE, priv->icmp_code))
goto nla_put_failure;
break;
+ default:
+ break;
}
return 0;
diff --git a/net/ipv4/netfilter/nft_reject_ipv4.c b/net/ipv4/netfilter/nft_reject_ipv4.c
index 16a5d4d..a7621fa 100644
--- a/net/ipv4/netfilter/nft_reject_ipv4.c
+++ b/net/ipv4/netfilter/nft_reject_ipv4.c
@@ -33,6 +33,8 @@ static void nft_reject_ipv4_eval(const struct nft_expr *expr,
case NFT_REJECT_TCP_RST:
nf_send_reset(pkt->skb, pkt->ops->hooknum);
break;
+ default:
+ break;
}
data[NFT_REG_VERDICT].verdict = NF_DROP;
diff --git a/net/ipv6/netfilter/nft_reject_ipv6.c b/net/ipv6/netfilter/nft_reject_ipv6.c
index f732859..71c7be5 100644
--- a/net/ipv6/netfilter/nft_reject_ipv6.c
+++ b/net/ipv6/netfilter/nft_reject_ipv6.c
@@ -34,6 +34,8 @@ static void nft_reject_ipv6_eval(const struct nft_expr *expr,
case NFT_REJECT_TCP_RST:
nf_send_reset6(net, pkt->skb, pkt->ops->hooknum);
break;
+ default:
+ break;
}
data[NFT_REG_VERDICT].verdict = NF_DROP;
diff --git a/net/netfilter/nft_compat.c b/net/netfilter/nft_compat.c
index 589b848..bdefefe 100644
--- a/net/netfilter/nft_compat.c
+++ b/net/netfilter/nft_compat.c
@@ -321,11 +321,11 @@ static void nft_match_eval(const struct nft_expr *expr,
return;
}
- switch(ret) {
- case true:
+ switch (ret ? 1 : 0) {
+ case 1:
data[NFT_REG_VERDICT].verdict = NFT_CONTINUE;
break;
- case false:
+ case 0:
data[NFT_REG_VERDICT].verdict = NFT_BREAK;
break;
}
diff --git a/net/netfilter/nft_ct.c b/net/netfilter/nft_ct.c
index cc56030..18d520e 100644
--- a/net/netfilter/nft_ct.c
+++ b/net/netfilter/nft_ct.c
@@ -56,6 +56,8 @@ static void nft_ct_get_eval(const struct nft_expr *expr,
state = NF_CT_STATE_BIT(ctinfo);
dest->data[0] = state;
return;
+ default:
+ break;
}
if (ct == NULL)
@@ -117,6 +119,8 @@ static void nft_ct_get_eval(const struct nft_expr *expr,
return;
}
#endif
+ default:
+ break;
}
tuple = &ct->tuplehash[priv->dir].tuple;
@@ -141,6 +145,8 @@ static void nft_ct_get_eval(const struct nft_expr *expr,
case NFT_CT_PROTO_DST:
dest->data[0] = (__force __u16)tuple->dst.u.all;
return;
+ default:
+ break;
}
return;
err:
@@ -172,6 +178,8 @@ static void nft_ct_set_eval(const struct nft_expr *expr,
}
break;
#endif
+ default:
+ break;
}
}
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] netfilter: Fix switch statement warnings with recent gcc.
2015-04-08 3:05 [PATCH] netfilter: Fix switch statement warnings with recent gcc David Miller
@ 2015-04-08 16:46 ` Pablo Neira Ayuso
2015-04-08 19:21 ` David Miller
0 siblings, 1 reply; 3+ messages in thread
From: Pablo Neira Ayuso @ 2015-04-08 16:46 UTC (permalink / raw)
To: David Miller; +Cc: netfilter-devel
On Tue, Apr 07, 2015 at 11:05:42PM -0400, David Miller wrote:
>
> More recent GCC warns about two kinds of switch statement uses:
>
> 1) Switching on an enumeration, but not having an explicit case
> statement for all members of the enumeration. To show the
> compiler this is intentional, we simply add a default case
> with nothing more than a break statement.
>
> 2) Switching on a boolean value. I think this warning is dumb
> but nevertheless you get it wholesale with -Wswitch.
>
> This patch cures all such warnings in netfilter.
>
> Signed-off-by: David S. Miller <davem@davemloft.net>
Acked-by: Pablo Neira Ayuso <pablo@netfilter.org>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] netfilter: Fix switch statement warnings with recent gcc.
2015-04-08 16:46 ` Pablo Neira Ayuso
@ 2015-04-08 19:21 ` David Miller
0 siblings, 0 replies; 3+ messages in thread
From: David Miller @ 2015-04-08 19:21 UTC (permalink / raw)
To: pablo; +Cc: netfilter-devel
From: Pablo Neira Ayuso <pablo@netfilter.org>
Date: Wed, 8 Apr 2015 18:46:14 +0200
> On Tue, Apr 07, 2015 at 11:05:42PM -0400, David Miller wrote:
>>
>> More recent GCC warns about two kinds of switch statement uses:
>>
>> 1) Switching on an enumeration, but not having an explicit case
>> statement for all members of the enumeration. To show the
>> compiler this is intentional, we simply add a default case
>> with nothing more than a break statement.
>>
>> 2) Switching on a boolean value. I think this warning is dumb
>> but nevertheless you get it wholesale with -Wswitch.
>>
>> This patch cures all such warnings in netfilter.
>>
>> Signed-off-by: David S. Miller <davem@davemloft.net>
>
> Acked-by: Pablo Neira Ayuso <pablo@netfilter.org>
Ok I tossed this into net-next, thanks for reviewing.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2015-04-08 19:21 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-04-08 3:05 [PATCH] netfilter: Fix switch statement warnings with recent gcc David Miller
2015-04-08 16:46 ` Pablo Neira Ayuso
2015-04-08 19:21 ` David Miller
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).