Skip to content

Commit 7b74913

Browse files
TropicaoPaolo Abeni
authored andcommitted
net: stmmac: fix multiplication overflow when reading timestamp
The current way of reading a timestamp snapshot in stmmac can lead to integer overflow, as the computation is done on 32 bits. The issue has been observed on a dwmac-socfpga platform returning chaotic timestamp values due to this overflow. The corresponding multiplication is done with a MUL instruction, which returns 32 bit values. Explicitly casting the value to 64 bits replaced the MUL with a UMLAL, which computes and returns the result on 64 bits, and so returns correctly the timestamps. Prevent this overflow by explicitly casting the intermediate value to u64 to make sure that the whole computation is made on u64. While at it, apply the same cast on the other dwmac variant (GMAC4) method for snapshot retrieval. Fixes: 477c3e1 ("net: stmmac: Introduce dwmac1000 timestamping operations") Signed-off-by: Alexis Lothoré <[email protected]> Reviewed-by: Maxime Chevallier <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Paolo Abeni <[email protected]>
1 parent 73fa459 commit 7b74913

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,7 @@ void dwmac1000_get_ptptime(void __iomem *ptpaddr, u64 *ptp_time)
553553
u64 ns;
554554

555555
ns = readl(ptpaddr + GMAC_PTP_ATNR);
556-
ns += readl(ptpaddr + GMAC_PTP_ATSR) * NSEC_PER_SEC;
556+
ns += (u64)readl(ptpaddr + GMAC_PTP_ATSR) * NSEC_PER_SEC;
557557

558558
*ptp_time = ns;
559559
}

drivers/net/ethernet/stmicro/stmmac/stmmac_hwtstamp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ static void get_ptptime(void __iomem *ptpaddr, u64 *ptp_time)
222222
u64 ns;
223223

224224
ns = readl(ptpaddr + PTP_ATNR);
225-
ns += readl(ptpaddr + PTP_ATSR) * NSEC_PER_SEC;
225+
ns += (u64)readl(ptpaddr + PTP_ATSR) * NSEC_PER_SEC;
226226

227227
*ptp_time = ns;
228228
}

0 commit comments

Comments
 (0)