]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
net: stmmac: make sure that ptp_rate is not 0 before configuring EST
authorAlexis Lothoré <alexis.lothore@bootlin.com>
Thu, 29 May 2025 09:07:24 +0000 (11:07 +0200)
committerJakub Kicinski <kuba@kernel.org>
Sat, 31 May 2025 02:33:29 +0000 (19:33 -0700)
If the ptp_rate recorded earlier in the driver happens to be 0, this
bogus value will propagate up to EST configuration, where it will
trigger a division by 0.

Prevent this division by 0 by adding the corresponding check and error
code.

Suggested-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
Signed-off-by: Alexis Lothoré <alexis.lothore@bootlin.com>
Fixes: 8572aec3d0dc ("net: stmmac: Add basic EST support for XGMAC")
Link: https://patch.msgid.link/20250529-stmmac_tstamp_div-v4-2-d73340a794d5@bootlin.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/ethernet/stmicro/stmmac/stmmac_est.c

index c9693f77e1f61fe5c92f95f5e544371445626c4d..ac6f2e3a3fcd2f9ae21913845282ff015cd2f7ec 100644 (file)
@@ -32,6 +32,11 @@ static int est_configure(struct stmmac_priv *priv, struct stmmac_est *cfg,
        int i, ret = 0;
        u32 ctrl;
 
+       if (!ptp_rate) {
+               netdev_warn(priv->dev, "Invalid PTP rate");
+               return -EINVAL;
+       }
+
        ret |= est_write(est_addr, EST_BTR_LOW, cfg->btr[0], false);
        ret |= est_write(est_addr, EST_BTR_HIGH, cfg->btr[1], false);
        ret |= est_write(est_addr, EST_TER, cfg->ter, false);