net: dsa: bcm_sf2: Use devm_clk_get_optional_enabled() calls in bcm_sf2_sw_probe()
Subsystems (5)
PATCH v2 1/1 net: dsa: bcm_sf2: Use devm_clk_get_optional_enabled() calls in bcm_sf2_sw_probe()
From: Markus Elfring <[email protected]>
Date: Fri, 20 Nov 2026 10:45:18 +0100
* Reuse existing functionality from devm_clk_get_optional_enabled() instead of keeping duplicate source code.
* Omit two clk_disable_unprepare() calls in the remove function and on error handling paths.
* Delete the labels “out_clk” and “out_clk_mdiv”.
This issue was detected by using the Coccinelle software.
---
V2:
Christophe Jaillet and Florian Fainelli requested further adjustments according to the proposed changes.
drivers/net/dsa/bcm_sf2.c | 29 +++++++---------------------- 1 file changed, 7 insertions(+), 22 deletions(-)
drivers/net/dsa/bcm_sf2.c +7 -22
@@ -1467,28 +1467,18 @@ static int bcm_sf2_sw_probe(struct platform_device *pdev) base++; } - priv->clk =devm_clk_get_optional (&pdev->dev,"sw_switch" ); + priv->clk =devm_clk_get_optional_enabled (&pdev->dev,"sw_switch" );if (IS_ERR (priv->clk))return PTR_ERR (priv->clk); - ret =clk_prepare_enable (priv->clk); -if (ret) -return ret; - - priv->clk_mdiv =devm_clk_get_optional (&pdev->dev,"sw_switch_mdiv" ); -if (IS_ERR (priv->clk_mdiv)) { - ret =PTR_ERR (priv->clk_mdiv); - goto out_clk; - } - - ret =clk_prepare_enable (priv->clk_mdiv); -if (ret) - goto out_clk; + priv->clk_mdiv =devm_clk_get_optional_enabled (&pdev->dev,"sw_switch_mdiv" ); +if (IS_ERR (priv->clk_mdiv)) +return PTR_ERR (priv->clk_mdiv); ret =bcm_sf2_sw_rst (priv);if (ret) {pr_err ("unable to software reset switch: %d\n" , ret); - goto out_clk_mdiv; +return ret; }bcm_sf2_crossbar_setup (priv);
@@ -1498,7 +1488,7 @@ static int bcm_sf2_sw_probe(struct platform_device *pdev) ret =bcm_sf2_mdio_register (ds);if (ret) {pr_err ("failed to register MDIO bus\n" ); - goto out_clk_mdiv; +return ret; }bcm_sf2_gphy_enable_set (priv->dev->ds, false);
@@ -1565,10 +1555,6 @@ static int bcm_sf2_sw_probe(struct platform_device *pdev) out_mdio:bcm_sf2_mdio_unregister (priv); -out_clk_mdiv: -clk_disable_unprepare (priv->clk_mdiv); -out_clk: -clk_disable_unprepare (priv->clk);return ret; }
@@ -1585,8 +1571,7 @@ static void bcm_sf2_sw_remove(struct platform_device *pdev)dsa_unregister_switch (priv->dev->ds);bcm_sf2_cfp_exit (priv->dev->ds);bcm_sf2_mdio_unregister (priv); -clk_disable_unprepare (priv->clk_mdiv); -clk_disable_unprepare (priv->clk); +if (priv->type ==BCM7278_DEVICE_ID )reset_control_assert (priv->rcdev); }
Signature · 1 line
2.56.1
This patch was applied to netdev/net-next.git (main) by Paolo Abeni <[email protected]>:
Hello:
This patch was applied to netdev/net-next.git (main) by Paolo Abeni <[email protected]>:
Quoted 10 lines · On Fri, 20 Nov 2026 11:18:20 +0100 you wrote:
From: Markus Elfring <[email protected]>
Date: Fri, 20 Nov 2026 10:45:18 +0100* Reuse existing functionality from
devm_clk_get_optional_enabled()instead of keeping duplicate source code.* Omit two
clk_disable_unprepare()calls in the remove function and on error handling paths.[...]
Here is the summary with links:
- [net-next,V2] net: dsa: bcm_sf2: Use devm_clk_get_optional_enabled() calls in bcm_sf2_sw_probe()
https://git.kernel.org/netdev/net-next/c/91cf0bf355c3
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html