diff options
author | Vladimir Oltean <vladimir.oltean@nxp.com> | 2021-02-15 15:31:43 +0200 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2021-02-15 12:42:19 -0800 |
commit | 1f778d500df3c0032a8ee1cd868ba60bd501b26b (patch) | |
tree | 1b20ab98813a34fb019ab48c9fc36e8c240210f3 /net/dsa | |
parent | d2a04370817fc7b0172dad2ef2decf907e1a304e (diff) |
net: mscc: ocelot: avoid type promotion when calling ocelot_ifh_set_dest
Smatch is confused by the fact that a 32-bit BIT(port) macro is passed
as argument to the ocelot_ifh_set_dest function and warns:
ocelot_xmit() warn: should '(((1))) << (dp->index)' be a 64 bit type?
seville_xmit() warn: should '(((1))) << (dp->index)' be a 64 bit type?
The destination port mask is copied into a 12-bit field of the packet,
starting at bit offset 67 and ending at 56.
So this DSA tagging protocol supports at most 12 bits, which is clearly
less than 32. Attempting to send to a port number > 12 will cause the
packing() call to truncate way before there will be 32-bit truncation
due to type promotion of the BIT(port) argument towards u64.
Therefore, smatch's fears that BIT(port) will do the wrong thing and
cause unexpected truncation for "port" values >= 32 are unfounded.
Nonetheless, let's silence the warning by explicitly passing an u64
value to ocelot_ifh_set_dest, such that the compiler does not need to do
a questionable type promotion.
Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/dsa')
-rw-r--r-- | net/dsa/tag_ocelot.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/net/dsa/tag_ocelot.c b/net/dsa/tag_ocelot.c index a7dd61c8e005..f9df9cac81c5 100644 --- a/net/dsa/tag_ocelot.c +++ b/net/dsa/tag_ocelot.c @@ -56,7 +56,7 @@ static struct sk_buff *ocelot_xmit(struct sk_buff *skb, void *injection; ocelot_xmit_common(skb, netdev, cpu_to_be32(0x8880000a), &injection); - ocelot_ifh_set_dest(injection, BIT(dp->index)); + ocelot_ifh_set_dest(injection, BIT_ULL(dp->index)); return skb; } @@ -68,7 +68,7 @@ static struct sk_buff *seville_xmit(struct sk_buff *skb, void *injection; ocelot_xmit_common(skb, netdev, cpu_to_be32(0x88800005), &injection); - seville_ifh_set_dest(injection, BIT(dp->index)); + seville_ifh_set_dest(injection, BIT_ULL(dp->index)); return skb; } |