]> git.ipfire.org Git - thirdparty/kernel/stable.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)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sun, 11 Jan 2026 14:22:32 +0000 (15:22 +0100)
commit cbefe2ffa7784525ec5d008ba87c7add19ec631a upstream.

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>
[ The context change is due to the commit c3f3b97238f6
  ("net: stmmac: Refactor EST implementation")
  which is irrelevant to the logic of this patch. ]
Signed-off-by: Rahul Sharma <black.hawk@163.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/net/ethernet/stmicro/stmmac/dwmac5.c
drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c

index 8fd167501fa0ea10a5f4489bc1d06fef6591b4d9..0afd4644a985f0eaf29f9c2c034126284a360809 100644 (file)
@@ -597,6 +597,11 @@ int dwmac5_est_configure(void __iomem *ioaddr, struct stmmac_est *cfg,
        int i, ret = 0x0;
        u32 ctrl;
 
+       if (!ptp_rate) {
+               pr_warn("Dwmac5: Invalid PTP rate");
+               return -EINVAL;
+       }
+
        ret |= dwmac5_est_write(ioaddr, BTR_LOW, cfg->btr[0], false);
        ret |= dwmac5_est_write(ioaddr, BTR_HIGH, cfg->btr[1], false);
        ret |= dwmac5_est_write(ioaddr, TER, cfg->ter, false);
index 0bcb378fa0bc9146a4c298fa678e88e9ca6951eb..aab02328a6130388263f0dab5ac0e801e67db6d6 100644 (file)
@@ -1537,6 +1537,11 @@ static int dwxgmac3_est_configure(void __iomem *ioaddr, struct stmmac_est *cfg,
        int i, ret = 0x0;
        u32 ctrl;
 
+        if (!ptp_rate) {
+                pr_warn("Dwxgmac2: Invalid PTP rate");
+                return -EINVAL;
+        }
+
        ret |= dwxgmac3_est_write(ioaddr, XGMAC_BTR_LOW, cfg->btr[0], false);
        ret |= dwxgmac3_est_write(ioaddr, XGMAC_BTR_HIGH, cfg->btr[1], false);
        ret |= dwxgmac3_est_write(ioaddr, XGMAC_TER, cfg->ter, false);