Skip to contentSkip to conversation

netfilter: nft_compat: fix sparse warning

PATCH Superseded Arturo Borrero Gonzalez 2 participants 4 messages Feb 12, 2015

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 netfilter: nft_compat: fix sparse warning

Quoted 1 line
Quoted 1 line

net/netfilter/nft_compat.c:140:37: sparse: incorrect type in assignment (different base types)

net/netfilter/nft_compat.c:140:37: expected restricted __be16 [usertype] ethproto
net/netfilter/nft_compat.c:140:37: got unsigned char [unsigned] [usertype] proto

Quoted 1 line
Quoted 1 line

net/netfilter/nft_compat.c:351:37: sparse: incorrect type in assignment (different base types)

net/netfilter/nft_compat.c:351:37: expected restricted __be16 [usertype] ethproto
net/netfilter/nft_compat.c:351:37: got unsigned char [unsigned] [usertype] proto

---
 net/netfilter/nft_compat.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
net/netfilter/nft_compat.c +2 -2
index c598f74..b5dc651 100644
@@ -137,7 +137,7 @@ nft_target_set_tgchk_param(struct xt_tgchk_param *par,
 		entry->e6.ipv6.invflags = inv ? IP6T_INV_PROTO : 0;
 		break;
 	case NFPROTO_BRIDGE:
-		entry->ebt.ethproto = proto;
+		entry->ebt.ethproto = (__force __be16)proto;
 		entry->ebt.invflags = inv ? EBT_IPROTO : 0;
 		break;
 	}
@@ -348,7 +348,7 @@ nft_match_set_mtchk_param(struct xt_mtchk_param *par, const struct nft_ctx *ctx,
 		entry->e6.ipv6.invflags = inv ? IP6T_INV_PROTO : 0;
 		break;
 	case NFPROTO_BRIDGE:
-		entry->ebt.ethproto = proto;
+		entry->ebt.ethproto = (__force __be16)proto;
 		entry->ebt.invflags = inv ? EBT_IPROTO : 0;
 		break;
 	}
#1 lore raw
Quoted 6 lines · Arturo Borrero Gonzalez
Quoted 1 line
Quoted 1 line

net/netfilter/nft_compat.c:140:37: sparse: incorrect type in assignment (different base types)

net/netfilter/nft_compat.c:140:37: expected restricted __be16 [usertype] ethproto
net/netfilter/nft_compat.c:140:37: got unsigned char [unsigned] [usertype] proto

Quoted 1 line
Quoted 1 line

net/netfilter/nft_compat.c:351:37: sparse: incorrect type in assignment (different base types)

net/netfilter/nft_compat.c:351:37: expected restricted __be16 [usertype] ethproto
net/netfilter/nft_compat.c:351:37: got unsigned char [unsigned] [usertype] proto

This is spotting a more serious problem. The existing code is trimming the ethernet protocol field to u8. We should use u16 all around the code and then force the casting to calm down sparse.

Quoted 29 lines
---
 net/netfilter/nft_compat.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
net/netfilter/nft_compat.c +2 -2
index c598f74..b5dc651 100644
@@ -137,7 +137,7 @@ nft_target_set_tgchk_param(struct xt_tgchk_param *par,
 		entry->e6.ipv6.invflags = inv ? IP6T_INV_PROTO : 0;
 		break;
 	case NFPROTO_BRIDGE:
-		entry->ebt.ethproto = proto;
+		entry->ebt.ethproto = (__force __be16)proto;
 		entry->ebt.invflags = inv ? EBT_IPROTO : 0;
 		break;
 	}
@@ -348,7 +348,7 @@ nft_match_set_mtchk_param(struct xt_mtchk_param *par, const struct nft_ctx *ctx,
 		entry->e6.ipv6.invflags = inv ? IP6T_INV_PROTO : 0;
 		break;
 	case NFPROTO_BRIDGE:
-		entry->ebt.ethproto = proto;
+		entry->ebt.ethproto = (__force __be16)proto;
 		entry->ebt.invflags = inv ? EBT_IPROTO : 0;
 		break;
 	}
#2 lore raw
Quoted 4 lines · Pablo Neira Ayuso
Quoted 3 lines · Arturo Borrero Gonzalez
Quoted 1 line
Quoted 1 line

net/netfilter/nft_compat.c:140:37: sparse: incorrect type in assignment (different base types)

net/netfilter/nft_compat.c:140:37: expected restricted __be16 [usertype] ethproto
net/netfilter/nft_compat.c:140:37: got unsigned char [unsigned] [usertype] proto

Quoted 8 lines
Quoted 3 lines
Quoted 1 line
Quoted 1 line

net/netfilter/nft_compat.c:351:37: sparse: incorrect type in assignment (different base types)

net/netfilter/nft_compat.c:351:37: expected restricted __be16 [usertype] ethproto
net/netfilter/nft_compat.c:351:37: got unsigned char [unsigned] [usertype] proto

This is spotting a more serious problem. The existing code is trimming the ethernet protocol field to u8. We should use u16 all around the code and then force the casting to calm down sparse.

I see, I can handle it if you want.

Signature · 5 lines
Arturo Borrero González
--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#3 lore raw
Quoted 6 lines · Arturo Borrero Gonzalez
Quoted 5 lines · Pablo Neira Ayuso
Quoted 4 lines · Arturo Borrero Gonzalez
Quoted 1 line
Quoted 1 line

net/netfilter/nft_compat.c:140:37: sparse: incorrect type in assignment (different base types)

net/netfilter/nft_compat.c:140:37: expected restricted __be16 [usertype] ethproto
net/netfilter/nft_compat.c:140:37: got unsigned char [unsigned] [usertype] proto

Quoted 1 line
Quoted 1 line

net/netfilter/nft_compat.c:351:37: sparse: incorrect type in assignment (different base types)

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

net/netfilter/nft_compat.c:351:37: expected restricted __be16 [usertype] ethproto
net/netfilter/nft_compat.c:351:37: got unsigned char [unsigned] [usertype] proto

This is spotting a more serious problem. The existing code is trimming the ethernet protocol field to u8. We should use u16 all around the code and then force the casting to calm down sparse.

I see, I can handle it if you want.

Please, go ahead. Thanks.