lkml.org 
[lkml]   [2021]   [Dec]   [6]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH v2] net: stmmac: Fix possible division by zero
Date
In stmmac_init_tstamp_counter() routine, there is a possiblity of division
by zero. If priv->plat->clk_ptp_rate becomes greater than 1 GHz,
config_sub_second_increment() subroutine may calculate sec_inc as zero
depending upon the PTP_TCR_TSCFUPDT register value, which will cause
divide by zero exception.

Fixes: a6da2bbb0005e ("net: stmmac: retain PTP clock time during SIOCSHWTSTAMP ioctls")
Addresses-Coverity: 1494557 ("Division or modulo by zero")
Signed-off-by: Ameer Hamza <amhamza.mgc@gmail.com>

---
Changes in v2:
Added fix tag, bug justification, and commit author.
---
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index da8306f60730..f44400323407 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -863,7 +863,7 @@ int stmmac_init_tstamp_counter(struct stmmac_priv *priv, u32 systime_flags)
stmmac_config_sub_second_increment(priv, priv->ptpaddr,
priv->plat->clk_ptp_rate,
xmac, &sec_inc);
- temp = div_u64(1000000000ULL, sec_inc);
+ temp = div_u64(1000000000ULL, (sec_inc > 0) ? sec_inc : 1);

/* Store sub second increment for later use */
priv->sub_second_inc = sec_inc;
--
2.25.1
\
 
 \ /
  Last update: 2021-12-06 15:25    [W:1.522 / U:0.116 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site