[PATCH v2] usb: chipidea: Use devm_clk_get_optional_enabled() in two probe functions

Markus Elfring posted 1 patch 2 days, 19 hours ago
drivers/usb/chipidea/ci_hdrc_npcm.c | 13 ++-----------
drivers/usb/chipidea/ci_hdrc_usb2.c | 15 ++-------------
2 files changed, 4 insertions(+), 24 deletions(-)
[PATCH v2] usb: chipidea: Use devm_clk_get_optional_enabled() in two probe functions
Posted by Markus Elfring 2 days, 19 hours ago
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sat, 21 Nov 2026 17:06:32 +0100

* Reuse existing functionality from devm_clk_get_optional_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.

* Delete the label “clk_err”.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---

V2:
Sashiko provided hints for further development considerations.
https://sashiko.dev/#/patchset/6d2450cf-9bbc-47b6-9ea3-f91bc1b91371%40web.de


 drivers/usb/chipidea/ci_hdrc_npcm.c | 13 ++-----------
 drivers/usb/chipidea/ci_hdrc_usb2.c | 15 ++-------------
 2 files changed, 4 insertions(+), 24 deletions(-)

diff --git a/drivers/usb/chipidea/ci_hdrc_npcm.c b/drivers/usb/chipidea/ci_hdrc_npcm.c
index 75a0223b578a..4b608f2bb383 100644
--- a/drivers/usb/chipidea/ci_hdrc_npcm.c
+++ b/drivers/usb/chipidea/ci_hdrc_npcm.c
@@ -47,14 +47,10 @@ static int npcm_udc_probe(struct platform_device *pdev)
 		return -ENOMEM;
 	platform_set_drvdata(pdev, ci);
 
-	ci->core_clk = devm_clk_get_optional(dev, NULL);
+	ci->core_clk = devm_clk_get_optional_enabled(dev, NULL);
 	if (IS_ERR(ci->core_clk))
 		return PTR_ERR(ci->core_clk);
 
-	ret = clk_prepare_enable(ci->core_clk);
-	if (ret)
-		return dev_err_probe(dev, ret, "failed to enable the clock: %d\n", ret);
-
 	ci->pdata.name = dev_name(dev);
 	ci->pdata.capoffset = DEF_CAPOFFSET;
 	ci->pdata.flags	= CI_HDRC_REQUIRES_ALIGNED_DMA |
@@ -67,17 +63,13 @@ static int npcm_udc_probe(struct platform_device *pdev)
 	if (IS_ERR(plat_ci)) {
 		ret = PTR_ERR(plat_ci);
 		dev_err(dev, "failed to register HDRC NPCM device: %d\n", ret);
-		goto clk_err;
+		return ret;
 	}
 
 	pm_runtime_no_callbacks(dev);
 	pm_runtime_enable(dev);
 
 	return 0;
-
-clk_err:
-	clk_disable_unprepare(ci->core_clk);
-	return ret;
 }
 
 static void npcm_udc_remove(struct platform_device *pdev)
@@ -86,7 +78,6 @@ static void npcm_udc_remove(struct platform_device *pdev)
 
 	pm_runtime_disable(&pdev->dev);
 	ci_hdrc_remove_device(ci->ci);
-	clk_disable_unprepare(ci->core_clk);
 }
 
 static const struct of_device_id npcm_udc_dt_match[] = {
diff --git a/drivers/usb/chipidea/ci_hdrc_usb2.c b/drivers/usb/chipidea/ci_hdrc_usb2.c
index b0200c5937cd..0cff5486e9c0 100644
--- a/drivers/usb/chipidea/ci_hdrc_usb2.c
+++ b/drivers/usb/chipidea/ci_hdrc_usb2.c
@@ -70,16 +70,10 @@ static int ci_hdrc_usb2_probe(struct platform_device *pdev)
 	if (!priv)
 		return -ENOMEM;
 
-	priv->clk = devm_clk_get_optional(dev, NULL);
+	priv->clk = devm_clk_get_optional_enabled(dev, NULL);
 	if (IS_ERR(priv->clk))
 		return PTR_ERR(priv->clk);
 
-	ret = clk_prepare_enable(priv->clk);
-	if (ret) {
-		dev_err(dev, "failed to enable the clock: %d\n", ret);
-		return ret;
-	}
-
 	ci_pdata->name = dev_name(dev);
 
 	priv->ci_pdev = ci_hdrc_add_device(dev, pdev->resource,
@@ -90,7 +84,7 @@ static int ci_hdrc_usb2_probe(struct platform_device *pdev)
 			dev_err(dev,
 				"failed to register ci_hdrc platform device: %d\n",
 				ret);
-		goto clk_err;
+		return ret;
 	}
 
 	platform_set_drvdata(pdev, priv);
@@ -99,10 +93,6 @@ static int ci_hdrc_usb2_probe(struct platform_device *pdev)
 	pm_runtime_enable(dev);
 
 	return 0;
-
-clk_err:
-	clk_disable_unprepare(priv->clk);
-	return ret;
 }
 
 static void ci_hdrc_usb2_remove(struct platform_device *pdev)
@@ -111,7 +101,6 @@ static void ci_hdrc_usb2_remove(struct platform_device *pdev)
 
 	pm_runtime_disable(&pdev->dev);
 	ci_hdrc_remove_device(priv->ci_pdev);
-	clk_disable_unprepare(priv->clk);
 }
 
 static struct platform_driver ci_hdrc_usb2_driver = {
-- 
2.56.1