Netdev List
 help / color / mirror / Atom feed
* [PATCH net-next] net: dsa: bcm_sf2: Use devm_clk_get_optional_enabled() in bcm_sf2_sw_probe()
@ 2026-11-19 16:37 Markus Elfring
  2026-11-19 17:45 ` Florian Fainelli
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Markus Elfring @ 2026-11-19 16:37 UTC (permalink / raw)
  To: netdev, Andrew Lunn, David S. Miller, Eric Dumazet,
	Florian Fainelli, Jakub Kicinski, Jonas Gorski, Paolo Abeni,
	Vladimir Oltean
  Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Thu, 19 Nov 2026 17:30: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/net/dsa/bcm_sf2.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/drivers/net/dsa/bcm_sf2.c b/drivers/net/dsa/bcm_sf2.c
index 1747a1f20c78..011ce79392e8 100644
--- a/drivers/net/dsa/bcm_sf2.c
+++ b/drivers/net/dsa/bcm_sf2.c
@@ -1467,14 +1467,10 @@ static int bcm_sf2_sw_probe(struct platform_device *pdev)
 		base++;
 	}
 
-	priv->clk = devm_clk_get_optional(&pdev->dev, "sw_switch");
+	priv->clk = devm_clk_get_optional_enabled(&pdev->dev, "sw_switch");
 	if (IS_ERR(priv->clk))
 		return PTR_ERR(priv->clk);
 
-	ret = clk_prepare_enable(priv->clk);
-	if (ret)
-		return ret;
-
 	priv->clk_mdiv = devm_clk_get_optional(&pdev->dev, "sw_switch_mdiv");
 	if (IS_ERR(priv->clk_mdiv)) {
 		ret = PTR_ERR(priv->clk_mdiv);
-- 
2.56.1


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

* Re: [PATCH net-next] net: dsa: bcm_sf2: Use devm_clk_get_optional_enabled() in bcm_sf2_sw_probe()
  2026-11-19 16:37 [PATCH net-next] net: dsa: bcm_sf2: Use devm_clk_get_optional_enabled() in bcm_sf2_sw_probe() Markus Elfring
@ 2026-11-19 17:45 ` Florian Fainelli
  2026-11-19 20:21 ` Christophe JAILLET
  2026-11-20 17:02 ` [PATCH net-next] " netdev-bot+sashiko
  2 siblings, 0 replies; 7+ messages in thread
From: Florian Fainelli @ 2026-11-19 17:45 UTC (permalink / raw)
  To: Markus Elfring, netdev, Andrew Lunn, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Jonas Gorski, Paolo Abeni,
	Vladimir Oltean
  Cc: LKML, kernel-janitors

On 11/19/26 08:37, Markus Elfring wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Thu, 19 Nov 2026 17:30: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>

Reviewed-by: Florian Fainelli <florian.fainelli@broadcom.com>
-- 
Florian

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

* Re: [PATCH net-next] net: dsa: bcm_sf2: Use devm_clk_get_optional_enabled() in bcm_sf2_sw_probe()
  2026-11-19 16:37 [PATCH net-next] net: dsa: bcm_sf2: Use devm_clk_get_optional_enabled() in bcm_sf2_sw_probe() Markus Elfring
  2026-11-19 17:45 ` Florian Fainelli
@ 2026-11-19 20:21 ` Christophe JAILLET
  2026-11-19 21:06   ` Florian Fainelli
  2026-11-20  6:54   ` Markus Elfring
  2026-11-20 17:02 ` [PATCH net-next] " netdev-bot+sashiko
  2 siblings, 2 replies; 7+ messages in thread
From: Christophe JAILLET @ 2026-11-19 20:21 UTC (permalink / raw)
  To: Markus Elfring, netdev, Andrew Lunn, David S. Miller,
	Eric Dumazet, Florian Fainelli, Jakub Kicinski, Jonas Gorski,
	Paolo Abeni, Vladimir Oltean
  Cc: LKML, kernel-janitors

Le 19/11/2026 à 17:37, Markus Elfring a écrit :
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Thu, 19 Nov 2026 17:30: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/net/dsa/bcm_sf2.c | 6 +-----
>   1 file changed, 1 insertion(+), 5 deletions(-)
> 
> diff --git a/drivers/net/dsa/bcm_sf2.c b/drivers/net/dsa/bcm_sf2.c
> index 1747a1f20c78..011ce79392e8 100644
> --- a/drivers/net/dsa/bcm_sf2.c
> +++ b/drivers/net/dsa/bcm_sf2.c
> @@ -1467,14 +1467,10 @@ static int bcm_sf2_sw_probe(struct platform_device *pdev)
>   		base++;
>   	}
>   
> -	priv->clk = devm_clk_get_optional(&pdev->dev, "sw_switch");
> +	priv->clk = devm_clk_get_optional_enabled(&pdev->dev, "sw_switch");
>   	if (IS_ERR(priv->clk))
>   		return PTR_ERR(priv->clk);
>   
> -	ret = clk_prepare_enable(priv->clk);
> -	if (ret)
> -		return ret;
> -
>   	priv->clk_mdiv = devm_clk_get_optional(&pdev->dev, "sw_switch_mdiv");
>   	if (IS_ERR(priv->clk_mdiv)) {
>   		ret = PTR_ERR(priv->clk_mdiv);

Hi,

NACK, this patch is wrong because the remove function and the error 
handling path of the probe need to be updated.

CJ

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

* Re: [PATCH net-next] net: dsa: bcm_sf2: Use devm_clk_get_optional_enabled() in bcm_sf2_sw_probe()
  2026-11-19 20:21 ` Christophe JAILLET
@ 2026-11-19 21:06   ` Florian Fainelli
  2026-11-20  7:00     ` Markus Elfring
  2026-11-20  6:54   ` Markus Elfring
  1 sibling, 1 reply; 7+ messages in thread
From: Florian Fainelli @ 2026-11-19 21:06 UTC (permalink / raw)
  To: Christophe JAILLET, Markus Elfring, netdev, Andrew Lunn,
	David S. Miller, Eric Dumazet, Jakub Kicinski, Jonas Gorski,
	Paolo Abeni, Vladimir Oltean
  Cc: LKML, kernel-janitors

On 11/19/26 12:21, Christophe JAILLET wrote:
> Le 19/11/2026 à 17:37, Markus Elfring a écrit :
>> From: Markus Elfring <elfring@users.sourceforge.net>
>> Date: Thu, 19 Nov 2026 17:30: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/net/dsa/bcm_sf2.c | 6 +-----
>>   1 file changed, 1 insertion(+), 5 deletions(-)
>>
>> diff --git a/drivers/net/dsa/bcm_sf2.c b/drivers/net/dsa/bcm_sf2.c
>> index 1747a1f20c78..011ce79392e8 100644
>> --- a/drivers/net/dsa/bcm_sf2.c
>> +++ b/drivers/net/dsa/bcm_sf2.c
>> @@ -1467,14 +1467,10 @@ static int bcm_sf2_sw_probe(struct 
>> platform_device *pdev)
>>           base++;
>>       }
>> -    priv->clk = devm_clk_get_optional(&pdev->dev, "sw_switch");
>> +    priv->clk = devm_clk_get_optional_enabled(&pdev->dev, "sw_switch");
>>       if (IS_ERR(priv->clk))
>>           return PTR_ERR(priv->clk);
>> -    ret = clk_prepare_enable(priv->clk);
>> -    if (ret)
>> -        return ret;
>> -
>>       priv->clk_mdiv = devm_clk_get_optional(&pdev->dev, 
>> "sw_switch_mdiv");
>>       if (IS_ERR(priv->clk_mdiv)) {
>>           ret = PTR_ERR(priv->clk_mdiv);
> 
> Hi,
> 
> NACK, this patch is wrong because the remove function and the error 
> handling path of the probe need to be updated.

My bad you are right this creates the following regressions: 
devm_clk_get_optional_enabled() registers a devres action that calls 
clk_disable_unprepare() on detach. The patch leaves the manual
clk_disable_unprepare(priv->clk) in two places in 
drivers/net/dsa/bcm_sf2.c: the probe error path (out_clk:) and 
bcm_sf2_sw_remove().

pw-bot: cr
-- 
Florian

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

* Re: net: dsa: bcm_sf2: Use devm_clk_get_optional_enabled() in bcm_sf2_sw_probe()
  2026-11-19 20:21 ` Christophe JAILLET
  2026-11-19 21:06   ` Florian Fainelli
@ 2026-11-20  6:54   ` Markus Elfring
  1 sibling, 0 replies; 7+ messages in thread
From: Markus Elfring @ 2026-11-20  6:54 UTC (permalink / raw)
  To: Christophe Jaillet, netdev, Andrew Lunn, David S. Miller,
	Eric Dumazet, Florian Fainelli, Jakub Kicinski, Jonas Gorski,
	Paolo Abeni, Vladimir Oltean
  Cc: LKML, kernel-janitors

> NACK, this patch is wrong because the remove function and the error handling path of the probe need to be updated.
Will further collateral evolution become possible?
https://elixir.bootlin.com/linux/v7.4-rc1/source/include/linux/clk.h#L680-L699
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/driver-api/driver-model/devres.rst?id=d220c9443db6e5f20a60cad55c6a0ae7a75c63b8#n242

https://elixir.bootlin.com/linux/v7.4-rc1/source/drivers/net/dsa/bcm_sf2.c#L1365-L1568

Regards,
Markus

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

* Re: net: dsa: bcm_sf2: Use devm_clk_get_optional_enabled() in bcm_sf2_sw_probe()
  2026-11-19 21:06   ` Florian Fainelli
@ 2026-11-20  7:00     ` Markus Elfring
  0 siblings, 0 replies; 7+ messages in thread
From: Markus Elfring @ 2026-11-20  7:00 UTC (permalink / raw)
  To: Florian Fainelli, Christophe Jaillet, netdev, Andrew Lunn,
	David S. Miller, Eric Dumazet, Jakub Kicinski, Jonas Gorski,
	Paolo Abeni, Vladimir Oltean
  Cc: LKML, kernel-janitors

>> NACK, this patch is wrong because the remove function and the error handling path of the probe need to be updated.
> 
> My bad you are right this creates the following regressions: devm_clk_get_optional_enabled() registers a devres action that calls clk_disable_unprepare() on detach. The patch leaves the manual
> clk_disable_unprepare(priv->clk) in two places in drivers/net/dsa/bcm_sf2.c: the probe error path (out_clk:) and bcm_sf2_sw_remove().
> 
> pw-bot: cr

Do you expect more functionality from a devm_clk_get_optional_enabled() call
than from the combination of devm_clk_get_optional() and clk_prepare_enable() so far?

https://elixir.bootlin.com/linux/v7.4-rc1/source/include/linux/clk.h#L680-L699
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/driver-api/driver-model/devres.rst?id=d220c9443db6e5f20a60cad55c6a0ae7a75c63b8#n242

https://elixir.bootlin.com/linux/v7.4-rc1/source/drivers/net/dsa/bcm_sf2.c#L1365-L1568

Regards,
Markus

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

* Re: [PATCH net-next] net: dsa: bcm_sf2: Use devm_clk_get_optional_enabled() in bcm_sf2_sw_probe()
  2026-11-19 16:37 [PATCH net-next] net: dsa: bcm_sf2: Use devm_clk_get_optional_enabled() in bcm_sf2_sw_probe() Markus Elfring
  2026-11-19 17:45 ` Florian Fainelli
  2026-11-19 20:21 ` Christophe JAILLET
@ 2026-11-20 17:02 ` netdev-bot+sashiko
  2 siblings, 0 replies; 7+ messages in thread
From: netdev-bot+sashiko @ 2026-11-20 17:02 UTC (permalink / raw)
  To: Markus.Elfring
  Cc: netdev, andrew, davem, edumazet, florian.fainelli, kuba,
	jonas.gorski, pabeni, olteanv, linux-kernel, kernel-janitors

Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.

Critical: 0 · High: 1 · Medium: 0 · Low: 1

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [High] The patch double-disables the switch clock.
- [Low] The commit message calls the change pure de-duplication ("Reuse
  existing functionality ... instead of keeping duplicate source code"),…

--

net: dsa: bcm_sf2: Use devm_clk_get_optional_enabled() in bcm_sf2_sw_probe()

This commit converts the "sw_switch" clock lookup in bcm_sf2_sw_probe()
from devm_clk_get_optional() followed by clk_prepare_enable() to
devm_clk_get_optional_enabled(). Coccinelle generated the change.

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

[Severity: Low]
This isn't a bug, but does this description match what the patch does?
The conversion changes behaviour. It adds a devres-managed
clk_disable_unprepare() for priv->clk and keeps the manual disables (see
the comment on the diff below).

In the patch as submitted, bcm_sf2_sw_remove() still tears down in the
original order:

drivers/net/dsa/bcm_sf2.c:bcm_sf2_sw_remove() {
    ...
	clk_disable_unprepare(priv->clk_mdiv);
	clk_disable_unprepare(priv->clk);
	if (priv->type == BCM7278_DEVICE_ID)
		reset_control_assert(priv->rcdev);
}

So the ordering is unchanged for now. Once the manual priv->clk disables
are dropped to fix the double-disable, devres would gate the sw_switch
clock after clk_mdiv is disabled. On BCM7278 it would also gate it after
reset_control_assert().

Could a respin describe and justify that ordering change? Could it also
explain why priv->clk_mdiv stays manually managed while priv->clk is
converted?

> diff --git a/drivers/net/dsa/bcm_sf2.c b/drivers/net/dsa/bcm_sf2.c
> index 1747a1f20c78e..011ce79392e8a 100644
> --- a/drivers/net/dsa/bcm_sf2.c
> +++ b/drivers/net/dsa/bcm_sf2.c
> @@ -1467,14 +1467,10 @@ static int bcm_sf2_sw_probe(struct platform_device *pdev)
>  		base++;
>  	}
>  
> -	priv->clk = devm_clk_get_optional(&pdev->dev, "sw_switch");
> +	priv->clk = devm_clk_get_optional_enabled(&pdev->dev, "sw_switch");
>  	if (IS_ERR(priv->clk))
>  		return PTR_ERR(priv->clk);
>  
> -	ret = clk_prepare_enable(priv->clk);
> -	if (ret)
> -		return ret;
> -

[Severity: High]
Is the sw_switch clock now disabled and unprepared twice?

devm_clk_get_optional_enabled() registers clk_disable_unprepare() as the
devres exit action:

drivers/clk/clk-devres.c:devm_clk_get_optional_enabled() {
	return __devm_clk_get(dev, id, clk_get_optional,
			      clk_prepare_enable, clk_disable_unprepare);
}

When devres is released, devm_clk_release() calls state->exit(state->clk).

The patch removes only the explicit clk_prepare_enable(priv->clk). The
explicit disable at the out_clk label is still there:

drivers/net/dsa/bcm_sf2.c:bcm_sf2_sw_probe() {
    ...
out_clk:
	clk_disable_unprepare(priv->clk);
	return ret;
}

So is the one in bcm_sf2_sw_remove():

	clk_disable_unprepare(priv->clk_mdiv);
	clk_disable_unprepare(priv->clk);

Every probe failure after the clock is acquired ends at out_clk. That
includes -EPROBE_DEFER from devm_clk_get_optional("sw_switch_mdiv"), so it
happens on every deferred probe retry. Unbind and module removal go
through bcm_sf2_sw_remove().

In both cases devres_release_all() runs afterwards and calls
clk_disable_unprepare() a second time.

When the sw_switch clock is present in DT, the second call would hit this
check in clk_core_disable():

	if (WARN(core->enable_count == 0, "%s already disabled\n", core->name))
		return;

It would also hit the matching "already unprepared" WARN in
clk_core_unprepare().

If the clk_core is shared with another consumer, would the extra call
drop that consumer's enable/prepare reference instead and gate a clock it
still uses?

Should clk_disable_unprepare(priv->clk) be removed from both the out_clk
path and bcm_sf2_sw_remove(), with the error labels adjusted to match?

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/d772ca26-d7f4-4857-9278-628b87e2252e%40web.de

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

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

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-19 16:37 [PATCH net-next] net: dsa: bcm_sf2: Use devm_clk_get_optional_enabled() in bcm_sf2_sw_probe() Markus Elfring
2026-11-19 17:45 ` Florian Fainelli
2026-11-19 20:21 ` Christophe JAILLET
2026-11-19 21:06   ` Florian Fainelli
2026-11-20  7:00     ` Markus Elfring
2026-11-20  6:54   ` Markus Elfring
2026-11-20 17:02 ` [PATCH net-next] " netdev-bot+sashiko

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