[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20240831021334.1907921-5-lizetao1@huawei.com>
Date: Sat, 31 Aug 2024 10:13:26 +0800
From: Li Zetao <lizetao1@...wei.com>
To: <florian.fainelli@...adcom.com>, <andrew@...n.ch>, <olteanv@...il.com>,
<davem@...emloft.net>, <edumazet@...gle.com>, <kuba@...nel.org>,
<pabeni@...hat.com>, <wens@...e.org>, <jernej.skrabec@...il.com>,
<samuel@...lland.org>, <heiko@...ech.de>, <yisen.zhuang@...wei.com>,
<salil.mehta@...wei.com>, <hauke@...ke-m.de>, <alexandre.torgue@...s.st.com>,
<joabreu@...opsys.com>, <mcoquelin.stm32@...il.com>, <wellslutw@...il.com>,
<radhey.shyam.pandey@....com>, <michal.simek@....com>,
<ajay.kathat@...rochip.com>, <claudiu.beznea@...on.dev>, <kvalo@...nel.org>,
<lizetao1@...wei.com>, <u.kleine-koenig@...gutronix.de>,
<jacky_chou@...eedtech.com>
CC: <netdev@...r.kernel.org>, <linux-arm-kernel@...ts.infradead.org>,
<linux-sunxi@...ts.linux.dev>, <linux-rockchip@...ts.infradead.org>,
<linux-stm32@...md-mailman.stormreply.com>, <linux-wireless@...r.kernel.org>
Subject: [PATCH net-next 04/12] net: ethernet: ethoc: Convert using devm_clk_get_enabled() in ethoc_probe()
Use devm_clk_get_enabled() instead of devm_clk_get() +
clk_prepare_enable(), which can make the clk consistent with the device
life cycle and reduce the risk of unreleased clk resources. Since the
device framework has automatically released the clk resource, there is
no need to execute clk_disable_unprepare(clk) on the error path, drop
the free2 label, and the meaning of the free3 label is not clear, Changing
it to free_mdiobus will make it more understandable.
Signed-off-by: Li Zetao <lizetao1@...wei.com>
---
drivers/net/ethernet/ethoc.c | 18 ++++++------------
1 file changed, 6 insertions(+), 12 deletions(-)
diff --git a/drivers/net/ethernet/ethoc.c b/drivers/net/ethernet/ethoc.c
index ad41c9019018..1a56e20cb679 100644
--- a/drivers/net/ethernet/ethoc.c
+++ b/drivers/net/ethernet/ethoc.c
@@ -1172,13 +1172,10 @@ static int ethoc_probe(struct platform_device *pdev)
/* Allow the platform setup code to adjust MII management bus clock. */
if (!eth_clkfreq) {
- struct clk *clk = devm_clk_get(&pdev->dev, NULL);
+ priv->clk = devm_clk_get_enabled(&pdev->dev, NULL);
- if (!IS_ERR(clk)) {
- priv->clk = clk;
- clk_prepare_enable(clk);
- eth_clkfreq = clk_get_rate(clk);
- }
+ if (!IS_ERR(priv->clk))
+ eth_clkfreq = clk_get_rate(priv->clk);
}
if (eth_clkfreq) {
u32 clkdiv = MIIMODER_CLKDIV(eth_clkfreq / 2500000 + 1);
@@ -1195,7 +1192,7 @@ static int ethoc_probe(struct platform_device *pdev)
priv->mdio = mdiobus_alloc();
if (!priv->mdio) {
ret = -ENOMEM;
- goto free2;
+ goto free;
}
priv->mdio->name = "ethoc-mdio";
@@ -1208,7 +1205,7 @@ static int ethoc_probe(struct platform_device *pdev)
ret = mdiobus_register(priv->mdio);
if (ret) {
dev_err(&netdev->dev, "failed to register MDIO bus\n");
- goto free3;
+ goto free_mdiobus;
}
ret = ethoc_mdio_probe(netdev);
@@ -1240,10 +1237,8 @@ static int ethoc_probe(struct platform_device *pdev)
netif_napi_del(&priv->napi);
error:
mdiobus_unregister(priv->mdio);
-free3:
+free_mdiobus:
mdiobus_free(priv->mdio);
-free2:
- clk_disable_unprepare(priv->clk);
free:
free_netdev(netdev);
out:
@@ -1267,7 +1262,6 @@ static void ethoc_remove(struct platform_device *pdev)
mdiobus_unregister(priv->mdio);
mdiobus_free(priv->mdio);
}
- clk_disable_unprepare(priv->clk);
unregister_netdev(netdev);
free_netdev(netdev);
}
--
2.34.1
Powered by blists - more mailing lists