diff mbox series

[net-next,09/12] net: ethernet: sunplus: Convert using devm_clk_get_enabled() in spl2sw_probe()

Message ID 20240831021334.1907921-10-lizetao1@huawei.com (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series net: Convert using devm_clk_get_enabled()/devm_clk_get_optional_enabled() | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 16 this patch: 16
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 5 of 5 maintainers
netdev/build_clang success Errors and warnings before: 16 this patch: 16
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 16 this patch: 16
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 60 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2024-08-31--15-00 (tests: 714)

Commit Message

Li Zetao Aug. 31, 2024, 2:13 a.m. UTC
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 label, and the original error process can return
directly. Some comments have also been adjusted.

Signed-off-by: Li Zetao <lizetao1@huawei.com>
---
 drivers/net/ethernet/sunplus/spl2sw_driver.c | 18 +++++-------------
 1 file changed, 5 insertions(+), 13 deletions(-)

Comments

Jakub Kicinski Sept. 3, 2024, 10:16 p.m. UTC | #1
On Sat, 31 Aug 2024 10:13:31 +0800 Li Zetao wrote:
> +	comm->clk = devm_clk_get_enabled(&pdev->dev, NULL);

You can remove clk from the driver struct now.
Please check if the same applies to other patches.
Li Zetao Sept. 4, 2024, 1:27 a.m. UTC | #2
Hi,

在 2024/9/4 6:16, Jakub Kicinski 写道:
> On Sat, 31 Aug 2024 10:13:31 +0800 Li Zetao wrote:
>> +	comm->clk = devm_clk_get_enabled(&pdev->dev, NULL);
> 
> You can remove clk from the driver struct now.
I don’t quite understand why clk can be removed from the driver struct, 
maybe I missed some important discussion information in the community, 
please let me know, thank you.
> Please check if the same applies to other patches.

Thanks,
Li Zetao.
Andrew Lunn Sept. 4, 2024, 5:20 a.m. UTC | #3
On Wed, Sep 04, 2024 at 09:27:06AM +0800, Li Zetao wrote:
> Hi,
> 
> 在 2024/9/4 6:16, Jakub Kicinski 写道:
> > On Sat, 31 Aug 2024 10:13:31 +0800 Li Zetao wrote:
> > > +	comm->clk = devm_clk_get_enabled(&pdev->dev, NULL);
> > 
> > You can remove clk from the driver struct now.
> I don’t quite understand why clk can be removed from the driver struct,

After you patch, where is it used?

	Andrew
diff mbox series

Patch

diff --git a/drivers/net/ethernet/sunplus/spl2sw_driver.c b/drivers/net/ethernet/sunplus/spl2sw_driver.c
index 391a1bc7f446..5944b96900b2 100644
--- a/drivers/net/ethernet/sunplus/spl2sw_driver.c
+++ b/drivers/net/ethernet/sunplus/spl2sw_driver.c
@@ -355,8 +355,8 @@  static int spl2sw_probe(struct platform_device *pdev)
 		return ret;
 	irq = ret;
 
-	/* Get clock controller. */
-	comm->clk = devm_clk_get(&pdev->dev, NULL);
+	/* Get and enable clock controller. */
+	comm->clk = devm_clk_get_enabled(&pdev->dev, NULL);
 	if (IS_ERR(comm->clk)) {
 		dev_err_probe(&pdev->dev, PTR_ERR(comm->clk),
 			      "Failed to retrieve clock controller!\n");
@@ -371,10 +371,6 @@  static int spl2sw_probe(struct platform_device *pdev)
 		return PTR_ERR(comm->rstc);
 	}
 
-	/* Enable clock. */
-	ret = clk_prepare_enable(comm->clk);
-	if (ret)
-		return ret;
 	udelay(1);
 
 	/* Reset MAC */
@@ -388,7 +384,7 @@  static int spl2sw_probe(struct platform_device *pdev)
 			       dev_name(&pdev->dev), comm);
 	if (ret) {
 		dev_err(&pdev->dev, "Failed to request irq #%d!\n", irq);
-		goto out_clk_disable;
+		return ret;
 	}
 
 	/* Initialize TX and RX descriptors. */
@@ -396,7 +392,7 @@  static int spl2sw_probe(struct platform_device *pdev)
 	if (ret) {
 		dev_err(&pdev->dev, "Fail to initialize mac descriptors!\n");
 		spl2sw_descs_free(comm);
-		goto out_clk_disable;
+		return ret;
 	}
 
 	/* Initialize MAC. */
@@ -406,7 +402,7 @@  static int spl2sw_probe(struct platform_device *pdev)
 	ret = spl2sw_mdio_init(comm);
 	if (ret) {
 		dev_err(&pdev->dev, "Failed to initialize mdio bus!\n");
-		goto out_clk_disable;
+		return ret;
 	}
 
 	/* Get child node ethernet-ports. */
@@ -506,8 +502,6 @@  static int spl2sw_probe(struct platform_device *pdev)
 out_free_mdio:
 	spl2sw_mdio_remove(comm);
 
-out_clk_disable:
-	clk_disable_unprepare(comm->clk);
 	return ret;
 }
 
@@ -536,8 +530,6 @@  static void spl2sw_remove(struct platform_device *pdev)
 	netif_napi_del(&comm->tx_napi);
 
 	spl2sw_mdio_remove(comm);
-
-	clk_disable_unprepare(comm->clk);
 }
 
 static const struct of_device_id spl2sw_of_match[] = {