[lvc-project] Fwd: [PATCH net] net: stmmac: prevent division by 0 in stmmac_init_tstamp_counter()

Sergey Shtylyov s.shtylyov at omp.ru
Tue Oct 7 23:12:11 MSK 2025


Вот - забыл lvc-project в CC добавить...

-------- Forwarded Message --------
Subject: [PATCH net] net: stmmac: prevent division by 0 in stmmac_init_tstamp_counter()
Date: Fri, 5 Sep 2025 19:06:50 +0300
From: Sergey Shtylyov <s.shtylyov at omp.ru>
Organization: Open Mobile Platform
To: Andrew Lunn <andrew+netdev at lunn.ch>, David S. Miller <davem at davemloft.net>, Eric Dumazet <edumazet at google.com>, Jakub Kicinski <kuba at kernel.org>, Paolo Abeni <pabeni at redhat.com>, Maxime Coquelin <mcoquelin.stm32 at gmail.com>, Alexandre Torgue <alexandre.torgue at foss.st.com>, netdev at vger.kernel.org, linux-stm32 at st-md-mailman.stormreply.com
CC: linux-arm-kernel at lists.infradead.org

In stmmac_init_tstamp_counter(), the sec_inc variable is initialized to 0,
and if stmmac_config_sub_second_increment() fails to set it to some non-0
value, the following div_u64() call would cause a kernel oops (because of
the divide error exception).  Let's check sec_inc for 0 before dividing by
it and just return -EINVAL if so...

Found by Linux Verification Center (linuxtesting.org) with the Svace static
analysis tool.

Fixes: df103170854e ("net: stmmac: Avoid sometimes uninitialized Clang warnings")
Signed-off-by: Sergey Shtylyov <s.shtylyov at omp.ru>

---
The patch is against the master branch of Linus Torvalds' linux.git repo.

 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c |    2 ++
 1 file changed, 2 insertions(+)

Index: linux/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
===================================================================
--- linux.orig/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ linux/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -817,6 +817,8 @@ int stmmac_init_tstamp_counter(struct st
 	stmmac_config_sub_second_increment(priv, priv->ptpaddr,
 					   priv->plat->clk_ptp_rate,
 					   xmac, &sec_inc);
+	if (!sec_inc)
+		return -EINVAL;
 	temp = div_u64(1000000000ULL, sec_inc);
 
 	/* Store sub second increment for later use */



More information about the lvc-project mailing list