Re: [PATCH 1/2] net: bonding: fix restricted __be16 degrades to integer

From: Jay Vosburgh
Date: Fri Mar 08 2019 - 15:54:56 EST


Bo YU <tsu.yubo@xxxxxxxxx> wrote:

>There are some warning when:
>
>sudo make C=1 CF=-D__CHECK_ENDIAN__ drivers/net/bonding/
>
>drivers/net/bonding/bond_main.c:2385:26: warning: restricted __be16 degrades to integer
>drivers/net/bonding/bond_main.c:2391:20: warning: restricted __be16 degrades to integer
>...
>drivers/net/bonding/bond_main.c:3241:60: warning: restricted __be16 degrades to integer
>drivers/net/bonding/bond_main.c:3241:60: warning: restricted __be16 degrades to integer
>
>So fix it.
>
>Signed-off-by: Bo YU <tsu.yubo@xxxxxxxxx>
>---
> 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 b59708c35faf..135fec28daa9 100644
>--- a/drivers/net/bonding/bond_main.c
>+++ b/drivers/net/bonding/bond_main.c
>@@ -2382,13 +2382,13 @@ static void bond_arp_send(struct net_device *slave_dev, int arp_op,
> return;
> }
>
>- if (!tags || tags->vlan_proto == VLAN_N_VID)
>+ if (!tags || be16_to_cpu(tags->vlan_proto) == VLAN_N_VID)
> goto xmit;
>
> tags++;
>
> /* Go through all the tags backwards and add them to the packet */
>- while (tags->vlan_proto != VLAN_N_VID) {
>+ while (be16_to_cpu(tags->vlan_proto) != VLAN_N_VID) {

I believe both of the above are incorrect, as vlan_proto is set
explicitly to VLAN_N_VID (in host byte order) by bond_verify_device_path
as a sentinel value. Byte swapping the tags->vlan_proto value would
cause the test or loop to miss the sentinel.


> if (!tags->vlan_id) {
> tags++;
> continue;
>@@ -3238,7 +3238,7 @@ static inline u32 bond_eth_hash(struct sk_buff *skb)
>
> ep = skb_header_pointer(skb, 0, sizeof(hdr_tmp), &hdr_tmp);
> if (ep)
>- return ep->h_dest[5] ^ ep->h_source[5] ^ ep->h_proto;
>+ return ep->h_dest[5] ^ ep->h_source[5] ^ be16_to_cpu(ep->h_proto);

This is probably harmless, other than adding work to the
transmit path.

-J

---
-Jay Vosburgh, jay.vosburgh@xxxxxxxxxxxxx