public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
From: Piergiorgio Beruto <piergiorgio.beruto@gmail.com>
To: kuba@kernel.org, netdev@vger.kernel.org
Cc: peppe.cavallaro@st.com, andrew@lunn.ch
Subject: [PATCH net] stmmac: fix potential division by 0
Date: Thu, 1 Dec 2022 01:37:08 +0100	[thread overview]
Message-ID: <Y4f3NGAZ2rqHkjWV@gvm01> (raw)

Depending on the HW platform and configuration, the
stmmac_config_sub_second_increment() function may return 0 in the
sec_inc variable. Therefore, the subsequent div_u64 operation can Oops
the kernel because of the divisor being 0.

Signed-off-by: Piergiorgio Beruto <piergiorgio.beruto@gmail.com>
---
 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 23ec0a9e396c..6ed1704b638d 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -848,7 +848,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, max_t(u32, sec_inc, 1));
 
 	/* Store sub second increment for later use */
 	priv->sub_second_inc = sec_inc;
-- 
2.35.1


             reply	other threads:[~2022-12-01  0:37 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-01  0:37 Piergiorgio Beruto [this message]
2022-12-01  1:39 ` [PATCH net] stmmac: fix potential division by 0 Andrew Lunn
2022-12-01 10:24   ` Piergiorgio Beruto
2022-12-01 14:49     ` Andrew Lunn
2022-12-02  8:26       ` Piergiorgio Beruto
2022-12-07  2:28       ` Jakub Kicinski
2022-12-07 13:48         ` Andrew Lunn
2022-12-07 14:50           ` Kurt Kanzenbach
2022-12-08  0:26             ` Andrew Lunn
2022-12-08  9:27               ` Piergiorgio Beruto
2022-12-10 10:50                 ` Andrew Lunn

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Y4f3NGAZ2rqHkjWV@gvm01 \
    --to=piergiorgio.beruto@gmail.com \
    --cc=andrew@lunn.ch \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=peppe.cavallaro@st.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox