DMA Engine development
 help / color / mirror / Atom feed
* [PATCH] dmaengine: dw: Use devm_clk_get_optional_enabled() in dw_probe()
@ 2026-11-19 16:06 Markus Elfring
  2026-11-19 16:12 ` sashiko-bot
  2026-11-19 17:16 ` Andy Shevchenko
  0 siblings, 2 replies; 8+ messages in thread
From: Markus Elfring @ 2026-11-19 16:06 UTC (permalink / raw)
  To: dmaengine, Andy Shevchenko, Frank Li, Vinod Koul, Viresh Kumar
  Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Thu, 19 Nov 2026 16:56:09 +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/dma/dw/platform.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/drivers/dma/dw/platform.c b/drivers/dma/dw/platform.c
index 7e76391475ac..9bb3c2cd0857 100644
--- a/drivers/dma/dw/platform.c
+++ b/drivers/dma/dw/platform.c
@@ -64,12 +64,9 @@ static int dw_probe(struct platform_device *pdev)
 
 	data->chip = chip;
 
-	chip->clk = devm_clk_get_optional(chip->dev, "hclk");
+	chip->clk = devm_clk_get_optional_enabled(chip->dev, "hclk");
 	if (IS_ERR(chip->clk))
 		return PTR_ERR(chip->clk);
-	ret = clk_prepare_enable(chip->clk);
-	if (ret)
-		return ret;
 
 	pm_runtime_enable(&pdev->dev);
 
-- 
2.56.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH] dmaengine: dw: Use devm_clk_get_optional_enabled() in dw_probe()
  2026-11-19 16:06 [PATCH] dmaengine: dw: Use devm_clk_get_optional_enabled() in dw_probe() Markus Elfring
@ 2026-11-19 16:12 ` sashiko-bot
  2026-11-19 16:53   ` Frank Li
  2026-11-19 17:16 ` Andy Shevchenko
  1 sibling, 1 reply; 8+ messages in thread
From: sashiko-bot @ 2026-11-19 16:12 UTC (permalink / raw)
  To: Markus Elfring, dmaengine; +Cc: vkoul, Frank.Li

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] dmaengine: dw: double clk_disable_unprepare() in dw_probe() and
  dw_remove()
--

commit ff07f5838666895fdb235cca7d9f7155e7085b00
Author: Markus Elfring <elfring@users.sourceforge.net>

dmaengine: dw: Use devm_clk_get_optional_enabled() in dw_probe()

This commit replaces devm_clk_get_optional() and clk_prepare_enable() in
dw_probe() with devm_clk_get_optional_enabled().

> diff --git a/drivers/dma/dw/platform.c b/drivers/dma/dw/platform.c
> index 7e76391475ac1..9bb3c2cd08570 100644
> --- a/drivers/dma/dw/platform.c
> +++ b/drivers/dma/dw/platform.c
> @@ -64,12 +64,9 @@ static int dw_probe(struct platform_device *pdev)
>  
>  	data->chip = chip;
>  
> -	chip->clk = devm_clk_get_optional(chip->dev, "hclk");
> +	chip->clk = devm_clk_get_optional_enabled(chip->dev, "hclk");
>  	if (IS_ERR(chip->clk))
>  		return PTR_ERR(chip->clk);
> -	ret = clk_prepare_enable(chip->clk);
> -	if (ret)
> -		return ret;
>  
>  	pm_runtime_enable(&pdev->dev);
>  

[Severity: High]
Does this cause a double clk_disable_unprepare() on chip->clk?

devm_clk_get_optional_enabled() registers a devres cleanup that disables
and unprepares chip->clk automatically, but both the err_dw_dma_probe
error path in dw_probe() and dw_remove() still call
clk_disable_unprepare(chip->clk) manually.  When data->probe() fails or
the device is unbound, chip->clk is disabled and unprepared twice,
underflowing the clock reference counts and triggering WARN() splats in
the clock core.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/8e3534b7-ae64-4c1f-819d-0ba390737b84@web.de?part=1

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] dmaengine: dw: Use devm_clk_get_optional_enabled() in dw_probe()
  2026-11-19 16:12 ` sashiko-bot
@ 2026-11-19 16:53   ` Frank Li
  2026-11-19 17:22     ` Markus Elfring
  0 siblings, 1 reply; 8+ messages in thread
From: Frank Li @ 2026-11-19 16:53 UTC (permalink / raw)
  To: sashiko-reviews; +Cc: Markus Elfring, dmaengine, vkoul, Frank.Li

On Thu, Nov 19, 2026 at 04:12:30PM +0000, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential
> issue to consider:
> - [High] dmaengine: dw: double clk_disable_unprepare() in dw_probe() and
>   dw_remove()
> --
>
> commit ff07f5838666895fdb235cca7d9f7155e7085b00
> Author: Markus Elfring <elfring@users.sourceforge.net>
>
> dmaengine: dw: Use devm_clk_get_optional_enabled() in dw_probe()
>
> This commit replaces devm_clk_get_optional() and clk_prepare_enable() in
> dw_probe() with devm_clk_get_optional_enabled().
>
> > diff --git a/drivers/dma/dw/platform.c b/drivers/dma/dw/platform.c
> > index 7e76391475ac1..9bb3c2cd08570 100644
> > --- a/drivers/dma/dw/platform.c
> > +++ b/drivers/dma/dw/platform.c
> > @@ -64,12 +64,9 @@ static int dw_probe(struct platform_device *pdev)
> >
> >  	data->chip = chip;
> >
> > -	chip->clk = devm_clk_get_optional(chip->dev, "hclk");
> > +	chip->clk = devm_clk_get_optional_enabled(chip->dev, "hclk");
> >  	if (IS_ERR(chip->clk))
> >  		return PTR_ERR(chip->clk);
> > -	ret = clk_prepare_enable(chip->clk);
> > -	if (ret)
> > -		return ret;
> >
> >  	pm_runtime_enable(&pdev->dev);
> >
>
> [Severity: High]
> Does this cause a double clk_disable_unprepare() on chip->clk?
>
> devm_clk_get_optional_enabled() registers a devres cleanup that disables
> and unprepares chip->clk automatically, but both the err_dw_dma_probe
> error path in dw_probe() and dw_remove() still call
> clk_disable_unprepare(chip->clk) manually.  When data->probe() fails or
> the device is unbound, chip->clk is disabled and unprepared twice,
> underflowing the clock reference counts and triggering WARN() splats in
> the clock core.

Please fix this problem

Frank

>
> --
> Sashiko AI review · https://sashiko.dev/#/patchset/8e3534b7-ae64-4c1f-819d-0ba390737b84@web.de?part=1

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] dmaengine: dw: Use devm_clk_get_optional_enabled() in dw_probe()
  2026-11-19 16:06 [PATCH] dmaengine: dw: Use devm_clk_get_optional_enabled() in dw_probe() Markus Elfring
  2026-11-19 16:12 ` sashiko-bot
@ 2026-11-19 17:16 ` Andy Shevchenko
  2026-11-19 17:27   ` Markus Elfring
  1 sibling, 1 reply; 8+ messages in thread
From: Andy Shevchenko @ 2026-11-19 17:16 UTC (permalink / raw)
  To: Markus Elfring
  Cc: dmaengine, Frank Li, Vinod Koul, Viresh Kumar, LKML,
	kernel-janitors

On Thu, Nov 19, 2026 at 05:06:55PM +0100, Markus Elfring wrote:
> 
> 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.

Something is wrong with your tools or scripts. It now brings a regression.

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] dmaengine: dw: Use devm_clk_get_optional_enabled() in dw_probe()
  2026-11-19 16:53   ` Frank Li
@ 2026-11-19 17:22     ` Markus Elfring
  2026-11-19 17:41       ` Frank Li
  0 siblings, 1 reply; 8+ messages in thread
From: Markus Elfring @ 2026-11-19 17:22 UTC (permalink / raw)
  To: Frank Li, sashiko-reviews, dmaengine
  Cc: Frank Li, Vinod Koul, LKML, kernel-janitors

>> Thank you for your contribution! Sashiko AI review found 1 potential
>> issue to consider:
>> - [High] dmaengine: dw: double clk_disable_unprepare() in dw_probe() and
>>   dw_remove()
>> --
>>
>> commit ff07f5838666895fdb235cca7d9f7155e7085b00
>> Author: Markus Elfring <elfring@users.sourceforge.net>
>>
>> dmaengine: dw: Use devm_clk_get_optional_enabled() in dw_probe()
>>
>> This commit replaces devm_clk_get_optional() and clk_prepare_enable() in
>> dw_probe() with devm_clk_get_optional_enabled().
>>
>>> diff --git a/drivers/dma/dw/platform.c b/drivers/dma/dw/platform.c
>>> index 7e76391475ac1..9bb3c2cd08570 100644
>>> --- a/drivers/dma/dw/platform.c
>>> +++ b/drivers/dma/dw/platform.c
>>> @@ -64,12 +64,9 @@ static int dw_probe(struct platform_device *pdev)
>>>
>>>  	data->chip = chip;
>>>
>>> -	chip->clk = devm_clk_get_optional(chip->dev, "hclk");
>>> +	chip->clk = devm_clk_get_optional_enabled(chip->dev, "hclk");
>>>  	if (IS_ERR(chip->clk))
>>>  		return PTR_ERR(chip->clk);
>>> -	ret = clk_prepare_enable(chip->clk);
>>> -	if (ret)
>>> -		return ret;
>>>
>>>  	pm_runtime_enable(&pdev->dev);
>>>
>>
>> [Severity: High]
>> Does this cause a double clk_disable_unprepare() on chip->clk?
>>
>> devm_clk_get_optional_enabled() registers a devres cleanup that disables
>> and unprepares chip->clk automatically, but both the err_dw_dma_probe
>> error path in dw_probe() and dw_remove() still call
>> clk_disable_unprepare(chip->clk) manually.  When data->probe() fails or
>> the device is unbound, chip->clk is disabled and unprepared twice,
>> underflowing the clock reference counts and triggering WARN() splats in
>> the clock core.
> 
> Please fix this problem

Do you find these two function calls really not equivalent to another known function call?
https://elixir.bootlin.com/linux/v7.4-rc1/source/include/linux/clk.h#L680-L699

Regards,
Markus


…
>> --
>> Sashiko AI review · https://sashiko.dev/#/patchset/8e3534b7-ae64-4c1f-819d-0ba390737b84@web.de?part=1


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: dmaengine: dw: Use devm_clk_get_optional_enabled() in dw_probe()
  2026-11-19 17:16 ` Andy Shevchenko
@ 2026-11-19 17:27   ` Markus Elfring
  2026-11-19 17:36     ` Andy Shevchenko
  0 siblings, 1 reply; 8+ messages in thread
From: Markus Elfring @ 2026-11-19 17:27 UTC (permalink / raw)
  To: Andy Shevchenko, dmaengine
  Cc: Frank Li, Vinod Koul, Viresh Kumar, LKML, kernel-janitors

>> 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.
> 
> Something is wrong with your tools or scripts. It now brings a regression.
Would you like to extend background information?

https://elixir.bootlin.com/linux/v7.4-rc1/source/include/linux/clk.h#L680-L699
…
 * devm_clk_get_optional_enabled - devm_clk_get_optional() +
 *                                 clk_prepare_enable()
…


Regards,
Markus

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: dmaengine: dw: Use devm_clk_get_optional_enabled() in dw_probe()
  2026-11-19 17:27   ` Markus Elfring
@ 2026-11-19 17:36     ` Andy Shevchenko
  0 siblings, 0 replies; 8+ messages in thread
From: Andy Shevchenko @ 2026-11-19 17:36 UTC (permalink / raw)
  To: Markus Elfring
  Cc: dmaengine, Frank Li, Vinod Koul, Viresh Kumar, LKML,
	kernel-janitors

On Thu, Nov 19, 2026 at 06:27:40PM +0100, Markus Elfring wrote:
> >> 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.
> > 
> > Something is wrong with your tools or scripts. It now brings a regression.
> Would you like to extend background information?

You are not the first year in this project, find the answer yourself.
Hint: what devm_*() actually do and when?

> https://elixir.bootlin.com/linux/v7.4-rc1/source/include/linux/clk.h#L680-L699
> …
>  * devm_clk_get_optional_enabled - devm_clk_get_optional() +
>  *                                 clk_prepare_enable()
> …

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] dmaengine: dw: Use devm_clk_get_optional_enabled() in dw_probe()
  2026-11-19 17:22     ` Markus Elfring
@ 2026-11-19 17:41       ` Frank Li
  0 siblings, 0 replies; 8+ messages in thread
From: Frank Li @ 2026-11-19 17:41 UTC (permalink / raw)
  To: Markus Elfring
  Cc: sashiko-reviews, dmaengine, Frank Li, Vinod Koul, LKML,
	kernel-janitors

On Thu, Nov 19, 2026 at 06:22:41PM +0100, Markus Elfring wrote:
> >> Thank you for your contribution! Sashiko AI review found 1 potential
> >> issue to consider:
> >> - [High] dmaengine: dw: double clk_disable_unprepare() in dw_probe() and
> >>   dw_remove()
> >> --
> >>
> >> commit ff07f5838666895fdb235cca7d9f7155e7085b00
> >> Author: Markus Elfring <elfring@users.sourceforge.net>
> >>
> >> dmaengine: dw: Use devm_clk_get_optional_enabled() in dw_probe()
> >>
> >> This commit replaces devm_clk_get_optional() and clk_prepare_enable() in
> >> dw_probe() with devm_clk_get_optional_enabled().
> >>
> >>> diff --git a/drivers/dma/dw/platform.c b/drivers/dma/dw/platform.c
> >>> index 7e76391475ac1..9bb3c2cd08570 100644
> >>> --- a/drivers/dma/dw/platform.c
> >>> +++ b/drivers/dma/dw/platform.c
> >>> @@ -64,12 +64,9 @@ static int dw_probe(struct platform_device *pdev)
> >>>
> >>>  	data->chip = chip;
> >>>
> >>> -	chip->clk = devm_clk_get_optional(chip->dev, "hclk");
> >>> +	chip->clk = devm_clk_get_optional_enabled(chip->dev, "hclk");
> >>>  	if (IS_ERR(chip->clk))
> >>>  		return PTR_ERR(chip->clk);
> >>> -	ret = clk_prepare_enable(chip->clk);
> >>> -	if (ret)
> >>> -		return ret;
> >>>
> >>>  	pm_runtime_enable(&pdev->dev);
> >>>
> >>
> >> [Severity: High]
> >> Does this cause a double clk_disable_unprepare() on chip->clk?
> >>
> >> devm_clk_get_optional_enabled() registers a devres cleanup that disables
> >> and unprepares chip->clk automatically, but both the err_dw_dma_probe
> >> error path in dw_probe() and dw_remove() still call
> >> clk_disable_unprepare(chip->clk) manually.  When data->probe() fails or
> >> the device is unbound, chip->clk is disabled and unprepared twice,
> >> underflowing the clock reference counts and triggering WARN() splats in
> >> the clock core.
> >
> > Please fix this problem
>
> Do you find these two function calls really not equivalent to another known function call?
> https://elixir.bootlin.com/linux/v7.4-rc1/source/include/linux/clk.h#L680-L699

What's your point? Sashiko just remind you need remove
clk unprepare at error path and remove() function

Frank
>
> Regards,
> Markus
>
>
> …
> >> --
> >> Sashiko AI review · https://sashiko.dev/#/patchset/8e3534b7-ae64-4c1f-819d-0ba390737b84@web.de?part=1
>

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2026-11-19 17:42 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-19 16:06 [PATCH] dmaengine: dw: Use devm_clk_get_optional_enabled() in dw_probe() Markus Elfring
2026-11-19 16:12 ` sashiko-bot
2026-11-19 16:53   ` Frank Li
2026-11-19 17:22     ` Markus Elfring
2026-11-19 17:41       ` Frank Li
2026-11-19 17:16 ` Andy Shevchenko
2026-11-19 17:27   ` Markus Elfring
2026-11-19 17:36     ` Andy Shevchenko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox