* [PATCH] usb: chipidea: Use devm_clk_get_optional_enabled() in two probe functions
@ 2026-11-19 18:43 Markus Elfring
2026-11-19 18:50 ` sashiko-bot
0 siblings, 1 reply; 2+ messages in thread
From: Markus Elfring @ 2026-11-19 18:43 UTC (permalink / raw)
To: linux-usb, openbmc, Andrew Jeffery, Avi Fishman, Benjamin Fair,
Greg Kroah-Hartman, Patrick Venture, Peter Chen, Tali Perry,
Tomer Maimon
Cc: LKML, kernel-janitors
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Thu, 19 Nov 2026 19:34:37 +0100
Reuse existing functionality from devm_clk_get_optional_enabled()
instead of keeping duplicate source code.
The source code was transformed by using the Coccinelle software.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
drivers/usb/chipidea/ci_hdrc_npcm.c | 6 +-----
drivers/usb/chipidea/ci_hdrc_usb2.c | 8 +-------
2 files changed, 2 insertions(+), 12 deletions(-)
diff --git a/drivers/usb/chipidea/ci_hdrc_npcm.c b/drivers/usb/chipidea/ci_hdrc_npcm.c
index 75a0223b578a..5052287f69c2 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 |
diff --git a/drivers/usb/chipidea/ci_hdrc_usb2.c b/drivers/usb/chipidea/ci_hdrc_usb2.c
index b0200c5937cd..d33ab6873def 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,
--
2.56.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] usb: chipidea: Use devm_clk_get_optional_enabled() in two probe functions
2026-11-19 18:43 [PATCH] usb: chipidea: Use devm_clk_get_optional_enabled() in two probe functions Markus Elfring
@ 2026-11-19 18:50 ` sashiko-bot
0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-11-19 18:50 UTC (permalink / raw)
To: Markus Elfring, linux-usb
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] usb: chipidea: npcm: double clk_disable_unprepare() on probe
err and remove
- [High] usb: chipidea: usb2: double clk_disable_unprepare() on probe
err and remove
--
commit f08588246bb9a1d0ba3a56c799e77b7dacaf4937
Author: Markus Elfring <elfring@users.sourceforge.net>
usb: chipidea: Use devm_clk_get_optional_enabled() in two probe functions
This commit replaces devm_clk_get_optional() and clk_prepare_enable() with
devm_clk_get_optional_enabled() in npcm_udc_probe() and ci_hdrc_usb2_probe().
> diff --git a/drivers/usb/chipidea/ci_hdrc_npcm.c b/drivers/usb/chipidea/ci_hdrc_npcm.c
> index 75a0223b578a8..5052287f69c2a 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 |
[Severity: High]
Does this cause clk_disable_unprepare(ci->core_clk) to run twice when
ci_hdrc_add_device() fails or when the device is removed?
devm_clk_get_optional_enabled() registers a devres action to disable and
unprepare ci->core_clk automatically, but both the clk_err error path in
npcm_udc_probe() and npcm_udc_remove() still call
clk_disable_unprepare(ci->core_clk) manually, underflowing the clock's
enable and prepare counts.
> diff --git a/drivers/usb/chipidea/ci_hdrc_usb2.c b/drivers/usb/chipidea/ci_hdrc_usb2.c
> index b0200c5937cd5..d33ab6873defb 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,
[Severity: High]
Similarly, won't priv->clk be disabled and unprepared twice if
ci_hdrc_add_device() fails (or returns -EPROBE_DEFER) or when
ci_hdrc_usb2_remove() runs?
The clk_err path in ci_hdrc_usb2_probe() and ci_hdrc_usb2_remove() still
call clk_disable_unprepare(priv->clk) before devres cleanup calls it a
second time.
--
Sashiko AI review · https://sashiko.dev/#/patchset/6d2450cf-9bbc-47b6-9ea3-f91bc1b91371@web.de?part=1
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-19 18:50 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-19 18:43 [PATCH] usb: chipidea: Use devm_clk_get_optional_enabled() in two probe functions Markus Elfring
2026-11-19 18:50 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox