netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] bonding: Always assign be16 value to vlan_proto
@ 2023-04-20 15:29 Simon Horman
  2023-04-20 19:47 ` Jay Vosburgh
  0 siblings, 1 reply; 7+ messages in thread
From: Simon Horman @ 2023-04-20 15:29 UTC (permalink / raw)
  To: Jakub Kicinski, David S. Miller, Eric Dumazet, Paolo Abeni
  Cc: Jay Vosburgh, Andy Gospodarek, netdev

The type of the vlan_proto field is __be16.
And most users of the field use it as such.

In the case of setting or testing the field for the
special VLAN_N_VID value, host byte order is used.
Which seems incorrect.

Address this issue by converting VLAN_N_VID to __be16.

I don't believe this is a bug because VLAN_N_VID in
both little-endian (and big-endian) byte order does
not conflict with any valid values (0 through VLAN_N_VID - 1)
in big-endian byte order.

Reported by sparse as:

 .../bond_main.c:2857:26: warning: restricted __be16 degrades to integer
 .../bond_main.c:2863:20: warning: restricted __be16 degrades to integer
 .../bond_main.c:2939:40: warning: incorrect type in assignment (different base types)
 .../bond_main.c:2939:40:    expected restricted __be16 [usertype] vlan_proto
 .../bond_main.c:2939:40:    got int

No functional changes intended.
Compile tested only.

Signed-off-by: Simon Horman <horms@kernel.org>
---
 drivers/net/bonding/bond_main.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
index db7e650d9ebb..7f4c75fe58e1 100644
--- a/drivers/net/bonding/bond_main.c
+++ b/drivers/net/bonding/bond_main.c
@@ -2854,13 +2854,13 @@ static bool bond_handle_vlan(struct slave *slave, struct bond_vlan_tag *tags,
 	struct net_device *slave_dev = slave->dev;
 	struct bond_vlan_tag *outer_tag = tags;
 
-	if (!tags || tags->vlan_proto == VLAN_N_VID)
+	if (!tags || tags->vlan_proto == cpu_to_be16(VLAN_N_VID))
 		return true;
 
 	tags++;
 
 	/* Go through all the tags backwards and add them to the packet */
-	while (tags->vlan_proto != VLAN_N_VID) {
+	while (tags->vlan_proto != cpu_to_be16(VLAN_N_VID)) {
 		if (!tags->vlan_id) {
 			tags++;
 			continue;
@@ -2936,7 +2936,7 @@ struct bond_vlan_tag *bond_verify_device_path(struct net_device *start_dev,
 		tags = kcalloc(level + 1, sizeof(*tags), GFP_ATOMIC);
 		if (!tags)
 			return ERR_PTR(-ENOMEM);
-		tags[level].vlan_proto = VLAN_N_VID;
+		tags[level].vlan_proto = cpu_to_be16(VLAN_N_VID);
 		return tags;
 	}
 


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

end of thread, other threads:[~2023-04-21 22:44 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-04-20 15:29 [PATCH] bonding: Always assign be16 value to vlan_proto Simon Horman
2023-04-20 19:47 ` Jay Vosburgh
2023-04-20 20:23   ` Vladimir Oltean
2023-04-20 21:23     ` Jay Vosburgh
2023-04-21  7:01       ` Simon Horman
2023-04-21  9:17         ` Vladimir Oltean
2023-04-21 22:34           ` Jay Vosburgh

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).