[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20240831021334.1907921-4-lizetao1@huawei.com>
Date: Sat, 31 Aug 2024 10:13:25 +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 03/12] net: ethernet: arc: Convert using devm_clk_get_enabled() in emac_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 out_clk_disable_unprepare label, and the original error process can
changed to the out_dispose_mapping error path.
Signed-off-by: Li Zetao <lizetao1@...wei.com>
---
drivers/net/ethernet/arc/emac_rockchip.c | 34 +++++-------------------
1 file changed, 6 insertions(+), 28 deletions(-)
diff --git a/drivers/net/ethernet/arc/emac_rockchip.c b/drivers/net/ethernet/arc/emac_rockchip.c
index 493d6356c8ca..22b3ebe059d9 100644
--- a/drivers/net/ethernet/arc/emac_rockchip.c
+++ b/drivers/net/ethernet/arc/emac_rockchip.c
@@ -144,7 +144,7 @@ static int emac_rockchip_probe(struct platform_device *pdev)
goto out_netdev;
}
- priv->refclk = devm_clk_get(dev, "macref");
+ priv->refclk = devm_clk_get_enabled(dev, "macref");
if (IS_ERR(priv->refclk)) {
dev_err(dev, "failed to retrieve reference clock (%ld)\n",
PTR_ERR(priv->refclk));
@@ -152,18 +152,12 @@ static int emac_rockchip_probe(struct platform_device *pdev)
goto out_netdev;
}
- err = clk_prepare_enable(priv->refclk);
- if (err) {
- dev_err(dev, "failed to enable reference clock (%d)\n", err);
- goto out_netdev;
- }
-
/* Optional regulator for PHY */
priv->regulator = devm_regulator_get_optional(dev, "phy");
if (IS_ERR(priv->regulator)) {
if (PTR_ERR(priv->regulator) == -EPROBE_DEFER) {
err = -EPROBE_DEFER;
- goto out_clk_disable;
+ goto out_netdev;
}
dev_err(dev, "no regulator found\n");
priv->regulator = NULL;
@@ -173,7 +167,7 @@ static int emac_rockchip_probe(struct platform_device *pdev)
err = regulator_enable(priv->regulator);
if (err) {
dev_err(dev, "failed to enable phy-supply (%d)\n", err);
- goto out_clk_disable;
+ goto out_netdev;
}
}
@@ -200,7 +194,7 @@ static int emac_rockchip_probe(struct platform_device *pdev)
}
if (priv->soc_data->need_div_macclk) {
- priv->macclk = devm_clk_get(dev, "macclk");
+ priv->macclk = devm_clk_get_enabled(dev, "macclk");
if (IS_ERR(priv->macclk)) {
dev_err(dev, "failed to retrieve mac clock (%ld)\n",
PTR_ERR(priv->macclk));
@@ -208,37 +202,26 @@ static int emac_rockchip_probe(struct platform_device *pdev)
goto out_regulator_disable;
}
- err = clk_prepare_enable(priv->macclk);
- if (err) {
- dev_err(dev, "failed to enable mac clock (%d)\n", err);
- goto out_regulator_disable;
- }
-
/* RMII TX/RX needs always a rate of 25MHz */
err = clk_set_rate(priv->macclk, 25000000);
if (err) {
dev_err(dev,
"failed to change mac clock rate (%d)\n", err);
- goto out_clk_disable_macclk;
+ goto out_regulator_disable;
}
}
err = arc_emac_probe(ndev, interface);
if (err) {
dev_err(dev, "failed to probe arc emac (%d)\n", err);
- goto out_clk_disable_macclk;
+ goto out_regulator_disable;
}
return 0;
-out_clk_disable_macclk:
- if (priv->soc_data->need_div_macclk)
- clk_disable_unprepare(priv->macclk);
out_regulator_disable:
if (priv->regulator)
regulator_disable(priv->regulator);
-out_clk_disable:
- clk_disable_unprepare(priv->refclk);
out_netdev:
free_netdev(ndev);
return err;
@@ -251,14 +234,9 @@ static void emac_rockchip_remove(struct platform_device *pdev)
arc_emac_remove(ndev);
- clk_disable_unprepare(priv->refclk);
-
if (priv->regulator)
regulator_disable(priv->regulator);
- if (priv->soc_data->need_div_macclk)
- clk_disable_unprepare(priv->macclk);
-
free_netdev(ndev);
}
--
2.34.1
Powered by blists - more mailing lists