public inbox for stable@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v6.6] net: stmmac: make sure that ptp_rate is not 0 before configuring EST
@ 2025-12-29  0:31 Rahul Sharma
  2026-01-08 11:09 ` Greg KH
  0 siblings, 1 reply; 2+ messages in thread
From: Rahul Sharma @ 2025-12-29  0:31 UTC (permalink / raw)
  To: gregkh, stable
  Cc: linux-kernel, Alexis Lothoré, Maxime Chevallier,
	Jakub Kicinski, Rahul Sharma

From: Alexis Lothoré <alexis.lothore@bootlin.com>

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>
---
 drivers/net/ethernet/stmicro/stmmac/dwmac5.c        | 5 +++++
 drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c | 5 +++++
 2 files changed, 10 insertions(+)

diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac5.c b/drivers/net/ethernet/stmicro/stmmac/dwmac5.c
index 8fd167501fa0..0afd4644a985 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac5.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac5.c
@@ -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);
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c
index 0bcb378fa0bc..aab02328a613 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c
@@ -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);
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v6.6] net: stmmac: make sure that ptp_rate is not 0 before configuring EST
  2025-12-29  0:31 [PATCH v6.6] net: stmmac: make sure that ptp_rate is not 0 before configuring EST Rahul Sharma
@ 2026-01-08 11:09 ` Greg KH
  0 siblings, 0 replies; 2+ messages in thread
From: Greg KH @ 2026-01-08 11:09 UTC (permalink / raw)
  To: Rahul Sharma
  Cc: stable, linux-kernel, Alexis Lothoré, Maxime Chevallier,
	Jakub Kicinski

On Mon, Dec 29, 2025 at 08:31:17AM +0800, Rahul Sharma wrote:
> From: Alexis Lothoré <alexis.lothore@bootlin.com>
> 
> 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>
> ---
>  drivers/net/ethernet/stmicro/stmmac/dwmac5.c        | 5 +++++
>  drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c | 5 +++++
>  2 files changed, 10 insertions(+)

What is the git id of this commit in Linus's tree?

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-01-08 11:09 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-29  0:31 [PATCH v6.6] net: stmmac: make sure that ptp_rate is not 0 before configuring EST Rahul Sharma
2026-01-08 11:09 ` Greg KH

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox