Skip to content

Commit 44abca1

Browse files
committed
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/[email protected] v2: https://lore.kernel.org/[email protected] v1: https://lore.kernel.org/[email protected] ==================== Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
2 parents 3ec5233 + cbefe2f commit 44abca1

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ static int est_configure(struct stmmac_priv *priv, struct stmmac_est *cfg,
3232
int i, ret = 0;
3333
u32 ctrl;
3434

35+
if (!ptp_rate) {
36+
netdev_warn(priv->dev, "Invalid PTP rate");
37+
return -EINVAL;
38+
}
39+
3540
ret |= est_write(est_addr, EST_BTR_LOW, cfg->btr[0], false);
3641
ret |= est_write(est_addr, EST_BTR_HIGH, cfg->btr[1], false);
3742
ret |= est_write(est_addr, EST_TER, cfg->ter, false);

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -805,6 +805,11 @@ int stmmac_init_tstamp_counter(struct stmmac_priv *priv, u32 systime_flags)
805805
if (!(priv->dma_cap.time_stamp || priv->dma_cap.atime_stamp))
806806
return -EOPNOTSUPP;
807807

808+
if (!priv->plat->clk_ptp_rate) {
809+
netdev_err(priv->dev, "Invalid PTP clock rate");
810+
return -EINVAL;
811+
}
812+
808813
stmmac_config_hw_tstamping(priv, priv->ptpaddr, systime_flags);
809814
priv->systime_flags = systime_flags;
810815

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ void stmmac_ptp_register(struct stmmac_priv *priv)
317317

318318
/* Calculate the clock domain crossing (CDC) error if necessary */
319319
priv->plat->cdc_error_adj = 0;
320-
if (priv->plat->has_gmac4 && priv->plat->clk_ptp_rate)
320+
if (priv->plat->has_gmac4)
321321
priv->plat->cdc_error_adj = (2 * NSEC_PER_SEC) / priv->plat->clk_ptp_rate;
322322

323323
/* Update the ptp clock parameters based on feature discovery, when

0 commit comments

Comments
 (0)