Netdev List
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: Markus.Elfring@web.de
Cc: netdev@vger.kernel.org, andrew@lunn.ch, davem@davemloft.net,
	edumazet@kernel.org, florian.fainelli@broadcom.com,
	kuba@kernel.org, jonas.gorski@gmail.com, pabeni@redhat.com,
	olteanv@gmail.com, linux-kernel@vger.kernel.org,
	kernel-janitors@vger.kernel.org
Subject: Re: [PATCH net-next] net: dsa: bcm_sf2: Use devm_clk_get_optional_enabled() in bcm_sf2_sw_probe()
Date: Fri, 20 Nov 2026 17:02:25 +0000	[thread overview]
Message-ID: <179519414508.3136.7413624094290164260@kernel.org> (raw)
In-Reply-To: <d772ca26-d7f4-4857-9278-628b87e2252e@web.de>

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

      parent reply	other threads:[~2026-11-20 17:02 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 ` netdev-bot+sashiko [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=179519414508.3136.7413624094290164260@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=Markus.Elfring@web.de \
    --cc=andrew@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=florian.fainelli@broadcom.com \
    --cc=jonas.gorski@gmail.com \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=olteanv@gmail.com \
    --cc=pabeni@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox