netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net]: bcmsysport: fix call balance of priv->clk handling routines
@ 2024-12-27 12:30 Vitalii Mordan
  2024-12-30 19:14 ` Florian Fainelli
  2024-12-31  1:40 ` patchwork-bot+netdevbpf
  0 siblings, 2 replies; 3+ messages in thread
From: Vitalii Mordan @ 2024-12-27 12:30 UTC (permalink / raw)
  To: Florian Fainelli
  Cc: Vitalii Mordan, Broadcom internal kernel review list, Andrew Lunn,
	David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	netdev, linux-kernel, Fedor Pchelkin, Alexey Khoroshilov,
	Vadim Mutilin

Check the return value of clk_prepare_enable to ensure that priv->clk has
been successfully enabled.

If priv->clk was not enabled during bcm_sysport_probe, bcm_sysport_resume,
or bcm_sysport_open, it must not be disabled in any subsequent execution
paths.

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

Fixes: 31bc72d97656 ("net: systemport: fetch and use clock resources")
Signed-off-by: Vitalii Mordan <mordan@ispras.ru>
---
 drivers/net/ethernet/broadcom/bcmsysport.c | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/broadcom/bcmsysport.c b/drivers/net/ethernet/broadcom/bcmsysport.c
index 42672c63f108..bc4e1f3b3752 100644
--- a/drivers/net/ethernet/broadcom/bcmsysport.c
+++ b/drivers/net/ethernet/broadcom/bcmsysport.c
@@ -1933,7 +1933,11 @@ static int bcm_sysport_open(struct net_device *dev)
 	unsigned int i;
 	int ret;
 
-	clk_prepare_enable(priv->clk);
+	ret = clk_prepare_enable(priv->clk);
+	if (ret) {
+		netdev_err(dev, "could not enable priv clock\n");
+		return ret;
+	}
 
 	/* Reset UniMAC */
 	umac_reset(priv);
@@ -2591,7 +2595,11 @@ static int bcm_sysport_probe(struct platform_device *pdev)
 		goto err_deregister_notifier;
 	}
 
-	clk_prepare_enable(priv->clk);
+	ret = clk_prepare_enable(priv->clk);
+	if (ret) {
+		dev_err(&pdev->dev, "could not enable priv clock\n");
+		goto err_deregister_netdev;
+	}
 
 	priv->rev = topctrl_readl(priv, REV_CNTL) & REV_MASK;
 	dev_info(&pdev->dev,
@@ -2605,6 +2613,8 @@ static int bcm_sysport_probe(struct platform_device *pdev)
 
 	return 0;
 
+err_deregister_netdev:
+	unregister_netdev(dev);
 err_deregister_notifier:
 	unregister_netdevice_notifier(&priv->netdev_notifier);
 err_deregister_fixed_link:
@@ -2774,7 +2784,12 @@ static int __maybe_unused bcm_sysport_resume(struct device *d)
 	if (!netif_running(dev))
 		return 0;
 
-	clk_prepare_enable(priv->clk);
+	ret = clk_prepare_enable(priv->clk);
+	if (ret) {
+		netdev_err(dev, "could not enable priv clock\n");
+		return ret;
+	}
+
 	if (priv->wolopts)
 		clk_disable_unprepare(priv->wol_clk);
 
-- 
2.25.1


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

* Re: [PATCH net]: bcmsysport: fix call balance of priv->clk handling routines
  2024-12-27 12:30 [PATCH net]: bcmsysport: fix call balance of priv->clk handling routines Vitalii Mordan
@ 2024-12-30 19:14 ` Florian Fainelli
  2024-12-31  1:40 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: Florian Fainelli @ 2024-12-30 19:14 UTC (permalink / raw)
  To: Vitalii Mordan
  Cc: Broadcom internal kernel review list, Andrew Lunn,
	David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	netdev, linux-kernel, Fedor Pchelkin, Alexey Khoroshilov,
	Vadim Mutilin

On 12/27/24 04:30, Vitalii Mordan wrote:
> Check the return value of clk_prepare_enable to ensure that priv->clk has
> been successfully enabled.
> 
> If priv->clk was not enabled during bcm_sysport_probe, bcm_sysport_resume,
> or bcm_sysport_open, it must not be disabled in any subsequent execution
> paths.
> 
> Found by Linux Verification Center (linuxtesting.org) with Klever.
> 
> Fixes: 31bc72d97656 ("net: systemport: fetch and use clock resources")
> Signed-off-by: Vitalii Mordan <mordan@ispras.ru>

Reviewed-by: Florian Fainelli <florian.fainelli@broadcom.com>
-- 
Florian

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

* Re: [PATCH net]: bcmsysport: fix call balance of priv->clk handling routines
  2024-12-27 12:30 [PATCH net]: bcmsysport: fix call balance of priv->clk handling routines Vitalii Mordan
  2024-12-30 19:14 ` Florian Fainelli
@ 2024-12-31  1:40 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2024-12-31  1:40 UTC (permalink / raw)
  To: Vitalii Mordan
  Cc: florian.fainelli, bcm-kernel-feedback-list, andrew+netdev, davem,
	edumazet, kuba, pabeni, netdev, linux-kernel, pchelkin,
	khoroshilov, mutilin

Hello:

This patch was applied to netdev/net.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Fri, 27 Dec 2024 15:30:07 +0300 you wrote:
> Check the return value of clk_prepare_enable to ensure that priv->clk has
> been successfully enabled.
> 
> If priv->clk was not enabled during bcm_sysport_probe, bcm_sysport_resume,
> or bcm_sysport_open, it must not be disabled in any subsequent execution
> paths.
> 
> [...]

Here is the summary with links:
  - [net] : bcmsysport: fix call balance of priv->clk handling routines
    https://git.kernel.org/netdev/net/c/b255ef45fcc2

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



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

end of thread, other threads:[~2024-12-31  1:40 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-12-27 12:30 [PATCH net]: bcmsysport: fix call balance of priv->clk handling routines Vitalii Mordan
2024-12-30 19:14 ` Florian Fainelli
2024-12-31  1:40 ` patchwork-bot+netdevbpf

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).