* [PATCH] net: phy: mdio-bcm-unimac: Cast denominator to unsigned long to avoid overflow
@ 2024-03-07 13:19 Daniil Dulov
2024-03-07 20:21 ` Florian Fainelli
0 siblings, 1 reply; 3+ messages in thread
From: Daniil Dulov @ 2024-03-07 13:19 UTC (permalink / raw)
To: Doug Berger
Cc: Daniil Dulov, Florian Fainelli,
Broadcom internal kernel review list, Andrew Lunn,
Heiner Kallweit, Russell King, David S. Miller, Eric Dumazet,
Jakub Kicinski, 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.
Fixes: b78ac6ecd1b6 ("net: phy: mdio-bcm-unimac: Allow configuring MDIO clock divider")
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 68f8ee0ec8ba..055102e6bb6d 100644
--- a/drivers/net/mdio/mdio-bcm-unimac.c
+++ b/drivers/net/mdio/mdio-bcm-unimac.c
@@ -192,7 +192,7 @@ static void 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");
return;
--
2.25.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] net: phy: mdio-bcm-unimac: Cast denominator to unsigned long to avoid overflow
2024-03-07 13:19 [PATCH] net: phy: mdio-bcm-unimac: Cast denominator to unsigned long to avoid overflow Daniil Dulov
@ 2024-03-07 20:21 ` Florian Fainelli
2024-03-09 3:52 ` Jakub Kicinski
0 siblings, 1 reply; 3+ messages in thread
From: Florian Fainelli @ 2024-03-07 20:21 UTC (permalink / raw)
To: Daniil Dulov, Doug Berger
Cc: Broadcom internal kernel review list, Andrew Lunn,
Heiner Kallweit, Russell King, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, netdev, linux-kernel, lvc-project
[-- Attachment #1: Type: text/plain, Size: 575 bytes --]
On 3/7/2024 5:19 AM, Daniil Dulov wrote:
> 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.
It will not in real life because the maximum clock frequency is 250MHz,
but it also does not hurt.
>
> Found by Linux Verification Center (linuxtesting.org) with SVACE.
>
> Fixes: b78ac6ecd1b6 ("net: phy: mdio-bcm-unimac: Allow configuring MDIO clock divider")
> Signed-off-by: Daniil Dulov <d.dulov@aladdin.ru>
Acked-by: Florian Fainelli <florian.fainelli@broadcom.com>
--
Florian
[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4221 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] net: phy: mdio-bcm-unimac: Cast denominator to unsigned long to avoid overflow
2024-03-07 20:21 ` Florian Fainelli
@ 2024-03-09 3:52 ` Jakub Kicinski
0 siblings, 0 replies; 3+ messages in thread
From: Jakub Kicinski @ 2024-03-09 3:52 UTC (permalink / raw)
To: Florian Fainelli
Cc: Daniil Dulov, Doug Berger, Broadcom internal kernel review list,
Andrew Lunn, Heiner Kallweit, Russell King, David S. Miller,
Eric Dumazet, Paolo Abeni, netdev, linux-kernel, lvc-project
On Thu, 7 Mar 2024 12:21:26 -0800 Florian Fainelli wrote:
> On 3/7/2024 5:19 AM, Daniil Dulov wrote:
> > 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.
>
> It will not in real life because the maximum clock frequency is 250MHz,
> but it also does not hurt.
If that's the case - Daniil, could you respin against net-next without
the Fixes tag? Otherwise it'll cause a conflict, if it's not a real
issue no point creating an extra hassle.
--
pw-bot: cr
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-03-09 3:52 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-03-07 13:19 [PATCH] net: phy: mdio-bcm-unimac: Cast denominator to unsigned long to avoid overflow Daniil Dulov
2024-03-07 20:21 ` Florian Fainelli
2024-03-09 3:52 ` Jakub Kicinski
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).