Skip to contentSkip to conversation

usb: bdc: Use devm_clk_get_optional_enabled() in bdc_probe()

PATCH New Markus Elfring 2 participants 2 messages Nov 21

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 usb: bdc: Use devm_clk_get_optional_enabled() in bdc_probe()

From: Markus Elfring <[email protected]>
Date: Sat, 21 Nov 2026 15:37:14 +0100

* Reuse existing functionality from devm_clk_get_optional_enabled() instead of keeping duplicate source code.

* Omit a clk_disable_unprepare() call on an error handling path and in the implementation of the function “bdc_remove”.

* Delete the label “disable_clk”.

This issue was detected by using the Coccinelle software.

---

V2:
Christophe Jaillet requested further adjustments according to the proposed changes.

  drivers/usb/gadget/udc/bdc/bdc_core.c | 13 ++-----------
 1 file changed, 2 insertions(+), 11 deletions(-)
drivers/usb/gadget/udc/bdc/bdc_core.c +2 -11
index 5149c98bf9bf..2369fbc1b70a 100644
@@ -530,20 +530,14 @@ static int bdc_probe(struct platform_device *pdev)
 		}
 	}
 
-	bdc->clk = devm_clk_get_optional(dev, "sw_usbd");
+	bdc->clk = devm_clk_get_optional_enabled(dev, "sw_usbd");
 	if (IS_ERR(bdc->clk))
 		return PTR_ERR(bdc->clk);
 
-	ret = clk_prepare_enable(bdc->clk);
-	if (ret) {
-		dev_err(dev, "could not enable clock\n");
-		return ret;
-	}
-
 	ret = bdc_phy_init(bdc);
 	if (ret) {
 		dev_err(bdc->dev, "BDC phy init failure:%d\n", ret);
-		goto disable_clk;
+		return ret;
 	}
 
 	temp = bdc_readl(bdc->regs, BDC_BDCCAP1);
@@ -576,8 +570,6 @@ static int bdc_probe(struct platform_device *pdev)
 	bdc_hw_exit(bdc);
 phycleanup:
 	bdc_phy_exit(bdc);
-disable_clk:
-	clk_disable_unprepare(bdc->clk);
 	return ret;
 }
 
@@ -610,7 +602,6 @@ static void bdc_remove(struct platform_device *pdev)
 	bdc_udc_exit(bdc);
 	bdc_hw_exit(bdc);
 	bdc_phy_exit(bdc);
-	clk_disable_unprepare(bdc->clk);
 }
 
 #ifdef CONFIG_PM_SLEEP
Signature · 1 line
2.56.1
#1 lore raw
Sashiko has reviewed this patch and found no issues.
Quoted 6 lines

From: Markus Elfring <[email protected]>
Date: Sat, 21 Nov 2026 15:37:14 +0100

* Reuse existing functionality from devm_clk_get_optional_enabled() instead of keeping duplicate source code.

Quoted 8 lines

* Omit a clk_disable_unprepare() call on an error handling path and in the implementation of the function “bdc_remove”.

* Delete the label “disable_clk”.

This issue was detected by using the Coccinelle software.

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1