linux/drivers/net/ethernet/stmicro/stmmac
Thomas Gleixner 3751c3d34c net: stmmac: Fix signed/unsigned wreckage
The recent addition of timestamp correction to compensate the CDC error
introduced a subtle signed/unsigned bug in stmmac_get_tx_hwtstamp() while
it managed for some obscure reason to avoid that in stmmac_get_rx_hwtstamp().

The issue is:

    s64 adjust = 0;
    u64 ns;

    adjust += -(2 * (NSEC_PER_SEC / priv->plat->clk_ptp_rate));
    ns += adjust;

works by chance on 64bit, but falls apart on 32bit because the compiler
knows that adjust fits into 32bit and then treats the addition as a u64 +
u32 resulting in an off by ~2 seconds failure.

The RX variant uses an u64 for adjust and does the adjustment via

    ns -= adjust;

because consistency is obviously overrated.

Get rid of the pointless zero initialized adjust variable and do:

	ns -= (2 * NSEC_PER_SEC) / priv->plat->clk_ptp_rate;

which is obviously correct and spares the adjust obfuscation. Aside of that
it yields a more accurate result because the multiplication takes place
before the integer divide truncation and not afterwards.

Stick the calculation into an inline so it can't be accidentally
disimproved. Return an u32 from that inline as the result is guaranteed
to fit which lets the compiler optimize the substraction.

Cc: stable@vger.kernel.org
Fixes: 3600be5f58 ("net: stmmac: add timestamp correction to rid CDC sync error")
Reported-by: Benedikt Spranger <b.spranger@linutronix.de>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Tested-by: Benedikt Spranger <b.spranger@linutronix.de>
Tested-by: Kurt Kanzenbach <kurt@linutronix.de> # Intel EHL
Link: https://lore.kernel.org/r/87mtm578cs.ffs@tglx
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2021-11-16 19:49:55 -08:00
..
altr_tse_pcs.c
altr_tse_pcs.h
chain_mode.c
common.h ethernet: constify references to netdev->dev_addr in drivers 2021-10-14 09:22:11 -07:00
descs_com.h
descs.h
dwmac4_core.c ethernet: constify references to netdev->dev_addr in drivers 2021-10-14 09:22:11 -07:00
dwmac4_descs.c net: stmmac: fix wrongly set buffer2 valid when sph unsupport 2021-02-26 15:17:11 -08:00
dwmac4_descs.h
dwmac4_dma.c net: stmmac: fix get_hw_feature() on old hardware 2021-10-08 16:22:38 +01:00
dwmac4_dma.h net: stmmac: Add HW descriptor prefetch setting for DWMAC Core 5.20 onwards 2021-04-22 15:02:40 -07:00
dwmac4_lib.c ethernet: constify references to netdev->dev_addr in drivers 2021-10-14 09:22:11 -07:00
dwmac4.h net: stmmac: Add hardware supported cross-timestamp 2021-03-24 15:12:36 -07:00
dwmac5.c net: stmmac: enable platform specific safety features 2021-06-01 16:59:50 -07:00
dwmac5.h net: stmmac: enable platform specific safety features 2021-06-01 16:59:50 -07:00
dwmac100_core.c ethernet: constify references to netdev->dev_addr in drivers 2021-10-14 09:22:11 -07:00
dwmac100_dma.c
dwmac100.h
dwmac1000_core.c ethernet: constify references to netdev->dev_addr in drivers 2021-10-14 09:22:11 -07:00
dwmac1000_dma.c net: stmmac: fix get_hw_feature() on old hardware 2021-10-08 16:22:38 +01:00
dwmac1000.h net: stmmac: dwmac1000: Fix extended MAC address registers definition 2021-06-11 13:05:55 -07:00
dwmac_dma.h net: stmmac: introduce DMA interrupt status masking per traffic direction 2021-03-25 17:37:30 -07:00
dwmac_lib.c ethernet: constify references to netdev->dev_addr in drivers 2021-10-14 09:22:11 -07:00
dwmac-anarion.c of: net: pass the dst buffer to of_get_mac_address() 2021-04-13 14:35:02 -07:00
dwmac-dwc-qos-eth.c of: net: pass the dst buffer to of_get_mac_address() 2021-04-13 14:35:02 -07:00
dwmac-generic.c net: stmmac: add support for dwmac 3.40a 2021-10-08 16:22:39 +01:00
dwmac-imx.c of: net: pass the dst buffer to of_get_mac_address() 2021-04-13 14:35:02 -07:00
dwmac-ingenic.c net: stmmac: Fix error return code in ingenic_mac_probe() 2021-06-16 12:02:38 -07:00
dwmac-intel-plat.c of: net: pass the dst buffer to of_get_mac_address() 2021-04-13 14:35:02 -07:00
dwmac-intel.c stmmac: intel: set PCI_D3hot in suspend 2021-06-29 11:34:48 -07:00
dwmac-intel.h stmmac: intel: move definitions to dwmac-intel header file 2021-06-12 13:10:52 -07:00
dwmac-ipq806x.c net: ethernet: stmmac: Do not use unreachable() in ipq806x_gmac_probe() 2021-08-07 09:45:46 +01:00
dwmac-loongson.c stmmac: dwmac-loongson:Fix missing return value 2021-09-06 12:52:52 +01:00
dwmac-lpc18xx.c of: net: pass the dst buffer to of_get_mac_address() 2021-04-13 14:35:02 -07:00
dwmac-mediatek.c of: net: pass the dst buffer to of_get_mac_address() 2021-04-13 14:35:02 -07:00
dwmac-meson8b.c of: net: pass the dst buffer to of_get_mac_address() 2021-04-13 14:35:02 -07:00
dwmac-meson.c of: net: pass the dst buffer to of_get_mac_address() 2021-04-13 14:35:02 -07:00
dwmac-oxnas.c of: net: pass the dst buffer to of_get_mac_address() 2021-04-13 14:35:02 -07:00
dwmac-qcom-ethqos.c net: stmmac: Use devm_platform_ioremap_resource_byname() 2021-06-09 15:24:43 -07:00
dwmac-rk.c net: stmmac: dwmac-rk: Fix ethernet on rk3399 based devices 2021-10-01 15:15:29 -07:00
dwmac-socfpga.c net: stmmac: socfpga: add runtime suspend/resume callback for stratix10 platform 2021-11-15 14:20:42 +00:00
dwmac-sti.c of: net: pass the dst buffer to of_get_mac_address() 2021-04-13 14:35:02 -07:00
dwmac-stm32.c of: net: pass the dst buffer to of_get_mac_address() 2021-04-13 14:35:02 -07:00
dwmac-sun8i.c ethernet: constify references to netdev->dev_addr in drivers 2021-10-14 09:22:11 -07:00
dwmac-sunxi.c net: stmicro: handle clk_prepare() failure during init 2021-05-13 17:33:18 +02:00
dwmac-visconti.c net: stmmac: dwmac-visconti: Make use of the helper function dev_err_probe() 2021-09-17 14:02:40 +01:00
dwxgmac2_core.c ethernet: constify references to netdev->dev_addr in drivers 2021-10-14 09:22:11 -07:00
dwxgmac2_descs.c net: stmmac: fix wrongly set buffer2 valid when sph unsupport 2021-02-26 15:17:11 -08:00
dwxgmac2_dma.c net: stmmac: fix get_hw_feature() on old hardware 2021-10-08 16:22:38 +01:00
dwxgmac2.h net: stmmac: introduce DMA interrupt status masking per traffic direction 2021-03-25 17:37:30 -07:00
dwxlgmac2.h
enh_desc.c net: stmmac: fix dma physical address of descriptor when display ring 2021-02-26 15:17:11 -08:00
hwif.c
hwif.h Merge git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net 2021-10-14 16:50:14 -07:00
Kconfig ethernet: fix PTP_1588_CLOCK dependencies 2021-08-13 17:49:05 -07:00
Makefile stmmac: pci: Add dwmac support for Loongson 2021-06-18 11:48:34 -07:00
mmc_core.c
mmc.h
norm_desc.c net: stmmac: fix dma physical address of descriptor when display ring 2021-02-26 15:17:11 -08:00
ring_mode.c
stmmac_ethtool.c ethtool: extend coalesce setting uAPI with CQE mode 2021-08-24 07:38:29 -07:00
stmmac_hwtstamp.c net: stmmac: Add support for external trigger timestamping 2021-04-14 12:57:45 -07:00
stmmac_main.c net: stmmac: Fix signed/unsigned wreckage 2021-11-16 19:49:55 -08:00
stmmac_mdio.c net: stmmac: reverse Christmas tree notation in stmmac_xpcs_setup 2021-06-11 13:43:55 -07:00
stmmac_pci.c net: stmmac: enable platform specific safety features 2021-06-01 16:59:50 -07:00
stmmac_pcs.h
stmmac_platform.c net: stmmac: add support for dwmac 3.40a 2021-10-08 16:22:39 +01:00
stmmac_platform.h of: net: pass the dst buffer to of_get_mac_address() 2021-04-13 14:35:02 -07:00
stmmac_ptp.c net: stmmac: ptp: update tas basetime after ptp adjust 2021-07-05 10:16:17 -07:00
stmmac_ptp.h net: stmmac: Add support for external trigger timestamping 2021-04-14 12:57:45 -07:00
stmmac_selftests.c ethernet: constify references to netdev->dev_addr in drivers 2021-10-14 09:22:11 -07:00
stmmac_tc.c net: stmmac: allow a tc-taprio base-time of zero 2021-11-10 14:32:15 +00:00
stmmac_xdp.c net: stmmac: fix kernel panic due to NULL pointer dereference of xsk_pool 2021-08-25 10:59:39 +01:00
stmmac_xdp.h net: stmmac: Enable RX via AF_XDP zero-copy 2021-04-13 15:06:51 -07:00
stmmac.h stmmac: Revert "stmmac: align RX buffers" 2021-08-20 14:44:49 -07:00