[PATCH net] net: stmmac: prevent division by 0 in stmmac_init_tstamp_counter()
Sergey Shtylyov
s.shtylyov at omp.ru
Fri Sep 5 09:06:50 PDT 2025
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 linux-arm-kernel
mailing list