Commit b2d12101 authored by Colin Ian King's avatar Colin Ian King Committed by David S. Miller

net: dsa: mv88e6xxx: avoid unintended sign extension on a 16 bit shift

The shifting of timehi by 16 bits to the left will be promoted to
a 32 bit signed int and then sign-extended to an u64. If the top bit
of timehi is set then all then all the upper bits of ns end up as also
being set because of the sign-extension. Fix this by making timehi and
timelo u64.  Also move the declaration of ns.

Detected by CoverityScan, CID#1465288 ("Unintended sign extension")

Fixes: c6fe0ad2 ("net: dsa: mv88e6xxx: add rx/tx timestamping support")
Signed-off-by: default avatarColin Ian King <colin.king@canonical.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 75efa06f
...@@ -293,7 +293,8 @@ static void mv88e6xxx_get_rxts(struct mv88e6xxx_chip *chip, ...@@ -293,7 +293,8 @@ static void mv88e6xxx_get_rxts(struct mv88e6xxx_chip *chip,
struct sk_buff *skb, u16 reg, struct sk_buff *skb, u16 reg,
struct sk_buff_head *rxq) struct sk_buff_head *rxq)
{ {
u16 buf[4] = { 0 }, status, timelo, timehi, seq_id; u16 buf[4] = { 0 }, status, seq_id;
u64 ns, timelo, timehi;
struct skb_shared_hwtstamps *shwt; struct skb_shared_hwtstamps *shwt;
int err; int err;
...@@ -321,7 +322,7 @@ static void mv88e6xxx_get_rxts(struct mv88e6xxx_chip *chip, ...@@ -321,7 +322,7 @@ static void mv88e6xxx_get_rxts(struct mv88e6xxx_chip *chip,
*/ */
for ( ; skb; skb = skb_dequeue(rxq)) { for ( ; skb; skb = skb_dequeue(rxq)) {
if (mv88e6xxx_ts_valid(status) && seq_match(skb, seq_id)) { if (mv88e6xxx_ts_valid(status) && seq_match(skb, seq_id)) {
u64 ns = timehi << 16 | timelo; ns = timehi << 16 | timelo;
mutex_lock(&chip->reg_lock); mutex_lock(&chip->reg_lock);
ns = timecounter_cyc2time(&chip->tstamp_tc, ns); ns = timecounter_cyc2time(&chip->tstamp_tc, ns);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment