Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge branch 'net-stmmac-prevent-div-by-0'

Alexis Lothoré says:

====================
net: stmmac: prevent div by 0

fix a small splat I am observing on a STM32MP157 platform at boot
(see commit 1) due to a division by 0.

v3: https://lore.kernel.org/20250528-stmmac_tstamp_div-v3-0-b525ecdfd84c@bootlin.com
v2: https://lore.kernel.org/20250527-stmmac_tstamp_div-v2-1-663251b3b542@bootlin.com
v1: https://lore.kernel.org/20250523-stmmac_tstamp_div-v1-1-bca8a5a3a477@bootlin.com
====================

Link: https://patch.msgid.link/20250529-stmmac_tstamp_div-v4-0-d73340a794d5@bootlin.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

+11 -1
+5
drivers/net/ethernet/stmicro/stmmac/stmmac_est.c
··· 32 32 int i, ret = 0; 33 33 u32 ctrl; 34 34 35 + if (!ptp_rate) { 36 + netdev_warn(priv->dev, "Invalid PTP rate"); 37 + return -EINVAL; 38 + } 39 + 35 40 ret |= est_write(est_addr, EST_BTR_LOW, cfg->btr[0], false); 36 41 ret |= est_write(est_addr, EST_BTR_HIGH, cfg->btr[1], false); 37 42 ret |= est_write(est_addr, EST_TER, cfg->ter, false);
+5
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
··· 805 805 if (!(priv->dma_cap.time_stamp || priv->dma_cap.atime_stamp)) 806 806 return -EOPNOTSUPP; 807 807 808 + if (!priv->plat->clk_ptp_rate) { 809 + netdev_err(priv->dev, "Invalid PTP clock rate"); 810 + return -EINVAL; 811 + } 812 + 808 813 stmmac_config_hw_tstamping(priv, priv->ptpaddr, systime_flags); 809 814 priv->systime_flags = systime_flags; 810 815
+1 -1
drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.c
··· 317 317 318 318 /* Calculate the clock domain crossing (CDC) error if necessary */ 319 319 priv->plat->cdc_error_adj = 0; 320 - if (priv->plat->has_gmac4 && priv->plat->clk_ptp_rate) 320 + if (priv->plat->has_gmac4) 321 321 priv->plat->cdc_error_adj = (2 * NSEC_PER_SEC) / priv->plat->clk_ptp_rate; 322 322 323 323 /* Update the ptp clock parameters based on feature discovery, when