Skip to contentSkip to conversation

netfilter: mark expected switch fall-throughs

PATCH In review Gustavo A. R. Silva 3 participants 6 messages Oct 19, 2017 – Nov 13, 2017

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 netfilter: mark expected switch fall-throughs

In preparation to enabling -Wimplicit-fallthrough, mark switch cases where we are expecting to fall through.

Notice that in some cases I placed the "fall through" comment on its own line, which is what GCC is expecting to find.

---
This code was tested by compilation only (GCC 7.2.0 was used). Please, verify if the actual intention of the code is to fall through.

 net/netfilter/ipset/ip_set_core.c      | 3 ++-
 net/netfilter/ipvs/ip_vs_proto_tcp.c   | 1 +
 net/netfilter/ipvs/ip_vs_proto_udp.c   | 1 +
 net/netfilter/nf_conntrack_h323_asn1.c | 3 +++
 net/netfilter/nft_cmp.c                | 2 ++
 net/netfilter/x_tables.c               | 3 ++-
 6 files changed, 11 insertions(+), 2 deletions(-)
net/netfilter/ipset/ip_set_core.c +2 -1
index cf84f7b..72f654a 100644
@@ -1386,7 +1386,8 @@ ip_set_dump_start(struct sk_buff *skb, struct netlink_callback *cb)
 				goto next_set;
 			if (set->variant->uref)
 				set->variant->uref(set, cb, true);
-			/* Fall through and add elements */
+			/* add elements */
+			/* fall through */
 		default:
 			rcu_read_lock_bh();
 			ret = set->variant->list(set, skb, cb);
net/netfilter/ipvs/ip_vs_proto_tcp.c +1 -0
index 1c6e101..569631d 100644
@@ -315,6 +315,7 @@ tcp_csum_check(int af, struct sk_buff *skb, struct ip_vs_protocol *pp)
 	switch (skb->ip_summed) {
 	case CHECKSUM_NONE:
 		skb->csum = skb_checksum(skb, tcphoff, skb->len - tcphoff, 0);
+		/* fall through */
 	case CHECKSUM_COMPLETE:
 #ifdef CONFIG_IP_VS_IPV6
 		if (af == AF_INET6) {
net/netfilter/ipvs/ip_vs_proto_udp.c +1 -0
index 30e11cd..c15ef7c 100644
@@ -319,6 +319,7 @@ udp_csum_check(int af, struct sk_buff *skb, struct ip_vs_protocol *pp)
 		case CHECKSUM_NONE:
 			skb->csum = skb_checksum(skb, udphoff,
 						 skb->len - udphoff, 0);
+			/* fall through */
 		case CHECKSUM_COMPLETE:
 #ifdef CONFIG_IP_VS_IPV6
 			if (af == AF_INET6) {
net/netfilter/nf_conntrack_h323_asn1.c +3 -0
index 89b2e46..7336e5c 100644
@@ -250,12 +250,15 @@ static unsigned int get_uint(bitstr_t *bs, int b)
 	case 4:
 		v |= *bs->cur++;
 		v <<= 8;
+		/* fall through */
 	case 3:
 		v |= *bs->cur++;
 		v <<= 8;
+		/* fall through */
 	case 2:
 		v |= *bs->cur++;
 		v <<= 8;
+		/* fall through */
 	case 1:
 		v |= *bs->cur++;
 		break;
net/netfilter/nft_cmp.c +2 -0
index c2945eb..fa90a84 100644
@@ -44,6 +44,7 @@ static void nft_cmp_eval(const struct nft_expr *expr,
 	case NFT_CMP_LT:
 		if (d == 0)
 			goto mismatch;
+		/* fall through */
 	case NFT_CMP_LTE:
 		if (d > 0)
 			goto mismatch;
@@ -51,6 +52,7 @@ static void nft_cmp_eval(const struct nft_expr *expr,
 	case NFT_CMP_GT:
 		if (d == 0)
 			goto mismatch;
+		/* fall through */
 	case NFT_CMP_GTE:
 		if (d < 0)
 			goto mismatch;
net/netfilter/x_tables.c +2 -1
index d8571f4..fa5cdd0 100644
@@ -1382,7 +1382,8 @@ static void *xt_mttg_seq_next(struct seq_file *seq, void *v, loff_t *ppos,
 		trav->curr = trav->curr->next;
 		if (trav->curr != trav->head)
 			break;
-		/* fallthru, _stop will unlock */
+		/* _stop will unlock */
+		/* fall through */
 	default:
 		return NULL;
 	}
Signature · 1 line
2.7.4
#1 lore raw

Hi Gustavo,

net/netfilter/ipset/ip_set_core.c ip_set_dump_start(struct sk_buff *skb, struct netlink_callback *cb) · line 1390

Quoted 11 lines · Gustavo A. R. Silva
net/netfilter/ipset/ip_set_core.c +2 -1
index cf84f7b..72f654a 100644
@@ -1386,7 +1386,8 @@ ip_set_dump_start(struct sk_buff *skb, struct netlink_callback *cb)
 				goto next_set;
 			if (set->variant->uref)
 				set->variant->uref(set, cb, true);
-			/* Fall through and add elements */
+			/* add elements */
+			/* fall through */

Just replace this comment by /* fall through */, I think it's enough to remember that this is intentional.

Quoted 3 lines
net/netfilter/ipset/ip_set_core.c +0 -0
 		default:
 			rcu_read_lock_bh();
 			ret = set->variant->list(set, skb, cb);

[...]

net/netfilter/x_tables.c static void *xt_mttg_seq_next(struct seq_file *seq, void *v, loff_t *ppos, · line 1385

Quoted 10 lines
net/netfilter/x_tables.c +1 -1
index d8571f4..fa5cdd0 100644
@@ -1382,7 +1382,8 @@ static void *xt_mttg_seq_next(struct seq_file *seq, void *v, loff_t *ppos,
 		trav->curr = trav->curr->next;
 		if (trav->curr != trav->head)
 			break;
-		/* fallthru, _stop will unlock */
+		/* _stop will unlock */

Same thing here, thanks!

#2 lore raw

Hello Pablo,

Quoting Pablo Neira Ayuso <[email protected]>:

Quoted 18 lines

Hi Gustavo,

net/netfilter/ipset/ip_set_core.c ip_set_dump_start(struct sk_buff *skb, struct · line 1391

Quoted 12 lines · Gustavo A. R. Silva
net/netfilter/ipset/ip_set_core.c +2 -1
index cf84f7b..72f654a 100644
@@ -1386,7 +1386,8 @@ ip_set_dump_start(struct sk_buff *skb, struct  
 netlink_callback *cb)
 				goto next_set;
 			if (set->variant->uref)
 				set->variant->uref(set, cb, true);
-			/* Fall through and add elements */
+			/* add elements */
+			/* fall through */

Just replace this comment by /* fall through */, I think it's enough to remember that this is intentional.

OK. Will do.

Quoted 5 lines
Quoted 4 lines
net/netfilter/ipset/ip_set_core.c +0 -0
 		default:
 			rcu_read_lock_bh();

ret = set->variant->list(set, skb, cb);

[...]

Quoted 13 lines

net/netfilter/x_tables.c static void *xt_mttg_seq_next(struct seq_file · line 1386

Quoted 11 lines
net/netfilter/x_tables.c +1 -1
index d8571f4..fa5cdd0 100644
@@ -1382,7 +1382,8 @@ static void *xt_mttg_seq_next(struct seq_file  
 *seq, void *v, loff_t *ppos,
 		trav->curr = trav->curr->next;
 		if (trav->curr != trav->head)
 			break;
-		/* fallthru, _stop will unlock */
+		/* _stop will unlock */

Same thing here, thanks!

OK. I will send v2 shortly.

Thanks for your comments
--
Gustavo A. R. Silva

#3 lore raw

PATCH v2 1/1 netfilter: mark expected switch fall-throughs

In preparation to enabling -Wimplicit-fallthrough, mark switch cases where we are expecting to fall through.

Addresses-Coverity-ID: 1128839
Addresses-Coverity-ID: 1128840
Addresses-Coverity-ID: 115120
Addresses-Coverity-ID: 115121

---
Changes in v2:
Replace code comments with "fall through" as suggested by Pablo Neira Ayuso. Add Coverity IDs to the changelog.

 net/netfilter/ipset/ip_set_core.c      | 2 +-
 net/netfilter/ipvs/ip_vs_proto_tcp.c   | 1 +
 net/netfilter/ipvs/ip_vs_proto_udp.c   | 1 +
 net/netfilter/nf_conntrack_h323_asn1.c | 3 +++
 net/netfilter/nft_cmp.c                | 2 ++
 net/netfilter/x_tables.c               | 2 +-
 6 files changed, 9 insertions(+), 2 deletions(-)
net/netfilter/ipset/ip_set_core.c +1 -1
index cf84f7b..d5a43ca 100644
@@ -1386,7 +1386,7 @@ ip_set_dump_start(struct sk_buff *skb, struct netlink_callback *cb)
 				goto next_set;
 			if (set->variant->uref)
 				set->variant->uref(set, cb, true);
-			/* Fall through and add elements */
+			/* fall through */
 		default:
 			rcu_read_lock_bh();
 			ret = set->variant->list(set, skb, cb);
net/netfilter/ipvs/ip_vs_proto_tcp.c +1 -0
index 1c6e101..569631d 100644
@@ -315,6 +315,7 @@ tcp_csum_check(int af, struct sk_buff *skb, struct ip_vs_protocol *pp)
 	switch (skb->ip_summed) {
 	case CHECKSUM_NONE:
 		skb->csum = skb_checksum(skb, tcphoff, skb->len - tcphoff, 0);
+		/* fall through */
 	case CHECKSUM_COMPLETE:
 #ifdef CONFIG_IP_VS_IPV6
 		if (af == AF_INET6) {
net/netfilter/ipvs/ip_vs_proto_udp.c +1 -0
index 30e11cd..c15ef7c 100644
@@ -319,6 +319,7 @@ udp_csum_check(int af, struct sk_buff *skb, struct ip_vs_protocol *pp)
 		case CHECKSUM_NONE:
 			skb->csum = skb_checksum(skb, udphoff,
 						 skb->len - udphoff, 0);
+			/* fall through */
 		case CHECKSUM_COMPLETE:
 #ifdef CONFIG_IP_VS_IPV6
 			if (af == AF_INET6) {
net/netfilter/nf_conntrack_h323_asn1.c +3 -0
index cf1bf26..c957fcf 100644
@@ -250,12 +250,15 @@ static unsigned int get_uint(struct bitstr *bs, int b)
 	case 4:
 		v |= *bs->cur++;
 		v <<= 8;
+		/* fall through */
 	case 3:
 		v |= *bs->cur++;
 		v <<= 8;
+		/* fall through */
 	case 2:
 		v |= *bs->cur++;
 		v <<= 8;
+		/* fall through */
 	case 1:
 		v |= *bs->cur++;
 		break;
net/netfilter/nft_cmp.c +2 -0
index c2945eb..fa90a84 100644
@@ -44,6 +44,7 @@ static void nft_cmp_eval(const struct nft_expr *expr,
 	case NFT_CMP_LT:
 		if (d == 0)
 			goto mismatch;
+		/* fall through */
 	case NFT_CMP_LTE:
 		if (d > 0)
 			goto mismatch;
@@ -51,6 +52,7 @@ static void nft_cmp_eval(const struct nft_expr *expr,
 	case NFT_CMP_GT:
 		if (d == 0)
 			goto mismatch;
+		/* fall through */
 	case NFT_CMP_GTE:
 		if (d < 0)
 			goto mismatch;
net/netfilter/x_tables.c +1 -1
index a77dd51..7c1414e 100644
@@ -1397,7 +1397,7 @@ static void *xt_mttg_seq_next(struct seq_file *seq, void *v, loff_t *ppos,
 		trav->curr = trav->curr->next;
 		if (trav->curr != trav->head)
 			break;
-		/* fallthru, _stop will unlock */
+		/* fall through */
 	default:
 		return NULL;
 	}
Signature · 1 line
2.7.4
maintainer Applied
#5 lore raw
Quoted 10 lines · Simon Horman
Quoted 8 lines · Gustavo A. R. Silva

In preparation to enabling -Wimplicit-fallthrough, mark switch cases where we are expecting to fall through.

Addresses-Coverity-ID: 1128839
Addresses-Coverity-ID: 1128840
Addresses-Coverity-ID: 115120
Addresses-Coverity-ID: 115121

Quoted 3 lines

Pablo, could you take this one directly?

Applied, thanks!