Skip to content

Commit b2d1210

Browse files
Colin Ian Kingdavem330
authored andcommitted
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: c6fe0ad ("net: dsa: mv88e6xxx: add rx/tx timestamping support") Signed-off-by: Colin Ian King <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 75efa06 commit b2d1210

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

drivers/net/dsa/mv88e6xxx/hwtstamp.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,8 @@ static void mv88e6xxx_get_rxts(struct mv88e6xxx_chip *chip,
293293
struct sk_buff *skb, u16 reg,
294294
struct sk_buff_head *rxq)
295295
{
296-
u16 buf[4] = { 0 }, status, timelo, timehi, seq_id;
296+
u16 buf[4] = { 0 }, status, seq_id;
297+
u64 ns, timelo, timehi;
297298
struct skb_shared_hwtstamps *shwt;
298299
int err;
299300

@@ -321,7 +322,7 @@ static void mv88e6xxx_get_rxts(struct mv88e6xxx_chip *chip,
321322
*/
322323
for ( ; skb; skb = skb_dequeue(rxq)) {
323324
if (mv88e6xxx_ts_valid(status) && seq_match(skb, seq_id)) {
324-
u64 ns = timehi << 16 | timelo;
325+
ns = timehi << 16 | timelo;
325326

326327
mutex_lock(&chip->reg_lock);
327328
ns = timecounter_cyc2time(&chip->tstamp_tc, ns);

0 commit comments

Comments
 (0)