netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next] net: phy: mdio-bcm-unimac: Cast denominator to unsigned long to avoid overflow
@ 2024-03-12 16:53 Daniil Dulov
  2024-03-12 17:16 ` Jakub Kicinski
  2024-03-12 17:18 ` Russell King (Oracle)
  0 siblings, 2 replies; 7+ messages in thread
From: Daniil Dulov @ 2024-03-12 16:53 UTC (permalink / raw)
  To: Jakub Kicinski, Florian Fainelli
  Cc: Daniil Dulov, Broadcom internal kernel review list, Andrew Lunn,
	Heiner Kallweit, Russell King, David S. Miller, Eric Dumazet,
	Doug Berger, Paolo Abeni, netdev, linux-kernel, lvc-project

The expression priv->clk_freq * 2 can lead to overflow that will cause
a division by zero. So, let's cast it to unsigned long to avoid it.

Found by Linux Verification Center (linuxtesting.org) with SVACE.

Signed-off-by: Daniil Dulov <d.dulov@aladdin.ru>
---
 drivers/net/mdio/mdio-bcm-unimac.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/mdio/mdio-bcm-unimac.c b/drivers/net/mdio/mdio-bcm-unimac.c
index f40eb50bb978..0425b622c09f 100644
--- a/drivers/net/mdio/mdio-bcm-unimac.c
+++ b/drivers/net/mdio/mdio-bcm-unimac.c
@@ -214,7 +214,7 @@ static int unimac_mdio_clk_set(struct unimac_mdio_priv *priv)
 	else
 		rate = clk_get_rate(priv->clk);
 
-	div = (rate / (2 * priv->clk_freq)) - 1;
+	div = (rate / (2 * (unsigned long)priv->clk_freq)) - 1;
 	if (div & ~MDIO_CLK_DIV_MASK) {
 		pr_warn("Incorrect MDIO clock frequency, ignoring\n");
 		ret = 0;
-- 
2.25.1


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

end of thread, other threads:[~2024-03-12 22:53 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-03-12 16:53 [PATCH net-next] net: phy: mdio-bcm-unimac: Cast denominator to unsigned long to avoid overflow Daniil Dulov
2024-03-12 17:16 ` Jakub Kicinski
2024-03-12 17:18 ` Russell King (Oracle)
2024-03-12 17:23   ` Florian Fainelli
2024-03-12 19:23     ` Doug Berger
2024-03-12 19:42       ` Russell King (Oracle)
2024-03-12 22:53         ` Doug Berger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).