bcm63xx_enet: Use devm_clk_get_enabled() in two probe functions
Subsystems (3)
PATCH 1/1 bcm63xx_enet: Use devm_clk_get_enabled() in two probe functions
From: Markus Elfring <[email protected]>
Date: Tue, 24 Nov 2026 19:50:57 +0100
* Reuse existing functionality from devm_clk_get_enabled() instead of keeping duplicate source code.
* Omit a clk_disable_unprepare() call on error handling paths and in the implementation of two remove functions.
* Omit two labels.
This issue was detected by using the Coccinelle software.
--- drivers/net/ethernet/broadcom/bcm63xx_enet.c | 26 ++++---------------- 1 file changed, 5 insertions(+), 21 deletions(-)
drivers/net/ethernet/broadcom/bcm63xx_enet.c +5 -21
@@ -1751,14 +1751,11 @@ static int bcm_enet_probe(struct platform_device *pdev) priv->irq_rx = irq_rx; priv->irq_tx = irq_tx; - priv->mac_clk =devm_clk_get (&pdev->dev,"enet" ); + priv->mac_clk =devm_clk_get_enabled (&pdev->dev,"enet" );if (IS_ERR (priv->mac_clk)) { ret =PTR_ERR (priv->mac_clk); goto out; } - ret =clk_prepare_enable (priv->mac_clk); -if (ret) - goto out;/* initialize default and fetch platform data */ priv->rx_ring_size =BCMENET_DEF_RX_DESC ;
@@ -1792,11 +1789,11 @@ static int bcm_enet_probe(struct platform_device *pdev)if (IS_ERR (priv->phy_clk)) { ret =PTR_ERR (priv->phy_clk); priv->phy_clk =NULL ; - goto out_disable_clk_mac; + goto out; } ret =clk_prepare_enable (priv->phy_clk);if (ret) - goto out_disable_clk_mac; + goto out; }/* do minimal hardware init to be able to probe mii bus */
@@ -1890,8 +1887,6 @@ static int bcm_enet_probe(struct platform_device *pdev)enet_writel (priv,0 ,ENET_MIISC_REG );clk_disable_unprepare (priv->phy_clk); -out_disable_clk_mac: -clk_disable_unprepare (priv->mac_clk); out:free_netdev (dev);return ret;
@@ -1926,9 +1921,7 @@ static void bcm_enet_remove(struct platform_device *pdev) bcm_enet_mdio_write_mii); } -/* disable hw block clocks */ clk_disable_unprepare (priv->phy_clk); -clk_disable_unprepare (priv->mac_clk);free_netdev (dev); }
@@ -2692,14 +2685,11 @@ static int bcm_enetsw_probe(struct platform_device *pdev) goto out; } - priv->mac_clk =devm_clk_get (&pdev->dev,"enetsw" ); + priv->mac_clk =devm_clk_get_enabled (&pdev->dev,"enetsw" );if (IS_ERR (priv->mac_clk)) { ret =PTR_ERR (priv->mac_clk); goto out; } - ret =clk_prepare_enable (priv->mac_clk); -if (ret) - goto out; priv->rx_chan =0 ; priv->tx_chan =1 ;
@@ -2718,7 +2708,7 @@ static int bcm_enetsw_probe(struct platform_device *pdev) ret =register_netdev (dev);if (ret) - goto out_disable_clk; + goto out;netif_carrier_off (dev);platform_set_drvdata (pdev, dev);
@@ -2727,8 +2717,6 @@ static int bcm_enetsw_probe(struct platform_device *pdev)return 0 ; -out_disable_clk: -clk_disable_unprepare (priv->mac_clk); out:free_netdev (dev);return ret;
@@ -2738,16 +2726,12 @@ static int bcm_enetsw_probe(struct platform_device *pdev)/* exit func, stops hardware and unregisters netdevice */ static void bcm_enetsw_remove (struct platform_device *pdev) { -struct bcm_enet_priv *priv;struct net_device *dev;/* stop netdevice */ dev =platform_get_drvdata (pdev); - priv =netdev_priv (dev);unregister_netdev (dev); -clk_disable_unprepare (priv->mac_clk); -free_netdev (dev); }
Signature · 1 line
2.56.1
Quoted 10 lines · Markus Elfring
* Reuse existing functionality from
devm_clk_get_enabled()instead of keeping duplicate source code.* Omit a
clk_disable_unprepare()call on error handling paths and in the implementation of two remove functions.* Omit two labels.
This issue was detected by using the Coccinelle software.
...
drivers/net/ethernet/broadcom/bcm63xx_enet.c static int bcm_enet_probe(struct platform_device *pdev) · line 1892
Quoted 5 lines
drivers/net/ethernet/broadcom/bcm63xx_enet.c +0
-2-out_disable_clk_mac: -clk_disable_unprepare (priv->mac_clk); out:free_netdev (dev);return ret;
Does this have side effects due to order changes? Same Q for the remove stage.
...
drivers/net/ethernet/broadcom/bcm63xx_enet.c static void bcm_enet_remove(struct platform_device *pdev) · line 1929
Quoted 1 line
drivers/net/ethernet/broadcom/bcm63xx_enet.c +0
-1-/* disable hw block clocks */
Why drop this comment?
Quoted 2 lines
(quoted diff) +0
-1clk_disable_unprepare(priv->phy_clk); - clk_disable_unprepare(priv->mac_clk);
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 9 lines
...
drivers/net/ethernet/broadcom/bcm63xx_enet.c static void bcm_enet_remove(struct platform_device *pdev) · line 1929
Quoted 1 line
drivers/net/ethernet/broadcom/bcm63xx_enet.c +0
-1-/* disable hw block clocks */ Why drop this comment?
Review
Quoted 2 lines
(quoted diff) +0
-1clk_disable_unprepare(priv->phy_clk); - clk_disable_unprepare(priv->mac_clk);
I propose to handle these clocks differently for the affected Linux driver.
https://elixir.bootlin.com/linux/v7.4-rc1/source/drivers/net/ethernet/broadcom/bcm63xx_enet.c#L1902-L1934
Regards,
Markus
Le 24/11/2026 à 20:23, Markus Elfring a écrit :
Quoted 112 lines
From: Markus Elfring <[email protected]>
Date: Tue, 24 Nov 2026 19:50:57 +0100* Reuse existing functionality from
devm_clk_get_enabled()instead of keeping duplicate source code.* Omit a
clk_disable_unprepare()call on error handling paths and in the implementation of two remove functions.* Omit two labels.
This issue was detected by using the Coccinelle software.
Signed-off-by Markus Elfring <[email protected]>--- drivers/net/ethernet/broadcom/bcm63xx_enet.c | 26 ++++---------------- 1 file changed, 5 insertions(+), 21 deletions(-)drivers/net/ethernet/broadcom/bcm63xx_enet.c +5
-18@@ -1751,14 +1751,11 @@ static int bcm_enet_probe(struct platform_device *pdev) priv->irq_rx = irq_rx; priv->irq_tx = irq_tx; - priv->mac_clk =devm_clk_get (&pdev->dev,"enet" ); + priv->mac_clk =devm_clk_get_enabled (&pdev->dev,"enet" );if (IS_ERR (priv->mac_clk)) { ret =PTR_ERR (priv->mac_clk); goto out; } - ret =clk_prepare_enable (priv->mac_clk); -if (ret) - goto out;/* initialize default and fetch platform data */ priv->rx_ring_size =BCMENET_DEF_RX_DESC ;@@ -1792,11 +1789,11 @@ static int bcm_enet_probe(struct platform_device *pdev)if (IS_ERR (priv->phy_clk)) { ret =PTR_ERR (priv->phy_clk); priv->phy_clk =NULL ; - goto out_disable_clk_mac; + goto out; } ret =clk_prepare_enable (priv->phy_clk);if (ret) - goto out_disable_clk_mac; + goto out; }/* do minimal hardware init to be able to probe mii bus */ @@ -1890,8 +1887,6 @@ static int bcm_enet_probe(struct platform_device *pdev)enet_writel (priv,0 ,ENET_MIISC_REG );clk_disable_unprepare (priv->phy_clk); -out_disable_clk_mac: -clk_disable_unprepare (priv->mac_clk); out:free_netdev (dev);return ret;@@ -1926,9 +1921,7 @@ static void bcm_enet_remove(struct platform_device *pdev) bcm_enet_mdio_write_mii); } -/* disable hw block clocks */ clk_disable_unprepare (priv->phy_clk); -clk_disable_unprepare (priv->mac_clk);free_netdev (dev); }@@ -2692,14 +2685,11 @@ static int bcm_enetsw_probe(struct platform_device *pdev) goto out; } - priv->mac_clk =devm_clk_get (&pdev->dev,"enetsw" ); + priv->mac_clk =devm_clk_get_enabled (&pdev->dev,"enetsw" );if (IS_ERR (priv->mac_clk)) { ret =PTR_ERR (priv->mac_clk); goto out; } - ret =clk_prepare_enable (priv->mac_clk); -if (ret) - goto out; priv->rx_chan =0 ; priv->tx_chan =1 ;@@ -2718,7 +2708,7 @@ static int bcm_enetsw_probe(struct platform_device *pdev) ret =register_netdev (dev);if (ret) - goto out_disable_clk; + goto out;netif_carrier_off (dev);platform_set_drvdata (pdev, dev);@@ -2727,8 +2717,6 @@ static int bcm_enetsw_probe(struct platform_device *pdev)return 0 ; -out_disable_clk: -clk_disable_unprepare (priv->mac_clk); out:free_netdev (dev);return ret;@@ -2738,16 +2726,12 @@ static int bcm_enetsw_probe(struct platform_device *pdev)/* exit func, stops hardware and unregisters netdevice */ static void bcm_enetsw_remove (struct platform_device *pdev) { -struct bcm_enet_priv *priv;struct net_device *dev;
drivers/net/ethernet/broadcom/bcm63xx_enet.c static int bcm_enetsw_probe(struct platform_device *pdev) · line 2737
Quoted 10 lines
drivers/net/ethernet/broadcom/bcm63xx_enet.c +0
-3/* stop netdevice */ dev =platform_get_drvdata (pdev); - priv =netdev_priv (dev);unregister_netdev (dev); -clk_disable_unprepare (priv->mac_clk); -free_netdev (dev); }
Why changing only one devm_clk_get()?
CJ
Quoted 1 line
Why changing only one
devm_clk_get()?
The change relevance is varying for the involved clocks of the affected Linux drivers, isn't it?
* bcm_enet_probe()
https://elixir.bootlin.com/linux/v7.4-rc1/source/drivers/net/ethernet/broadcom/bcm63xx_enet.c#L1711-L1898
* bcm_enetsw_probe()
https://elixir.bootlin.com/linux/v7.4-rc1/source/drivers/net/ethernet/broadcom/bcm63xx_enet.c#L2641-L2735
Regards,
Markus