Netdev List
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: Markus.Elfring@web.de
Cc: netdev@vger.kernel.org, andrew+netdev@lunn.ch,
	davem@davemloft.net, edumazet@kernel.org,
	hemanth.selam@gmail.com, kuba@kernel.org, jonas.gorski@gmail.com,
	pabeni@redhat.com, horms@kernel.org,
	linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org,
	andriy.shevchenko@linux.intel.com, christophe.jaillet@wanadoo.fr,
	f.fainelli@gmail.com, Frank.Li@kernel.org, Julia.Lawall@inria.fr
Subject: Re: [PATCH net v2 1/2] bcm63xx_enet: Prevent unbalanced clk_disable_unprepare() call in bcm_enet_remove()
Date: Sat, 28 Nov 2026 14:31:58 +0000	[thread overview]
Message-ID: <179587631846.3135.16815258842003970286@kernel.org> (raw)
In-Reply-To: <0302adc3-dbf2-4e62-ac9b-8923ac285506@web.de>

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

Critical: 0 · High: 0 (1) · Medium: 1 · Low: 2

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).

- [Medium] The patch fixes a bug that does not exist, but carries Fixes:
  and Cc: stable tags.
- [Low] The patch guards clk_disable_unprepare(priv->phy_clk) in
  bcm_enet_remove() but leaves the identical unconditional call at the…
- [Low] In bcm_enet_remove() the patch moves
  clk_disable_unprepare(priv->phy_clk) ahead of…

Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but it is in the
  same probe/remove pair and survives the whole series.

--

bcm63xx_enet: Prevent unbalanced clk_disable_unprepare() call in bcm_enet_remove()

This patch moves clk_disable_unprepare(priv->phy_clk) in bcm_enet_remove()
into the has_phy branch and guards it with !priv->use_external_mii. That
matches the condition under which bcm_enet_probe() enables the clock. The
patch has a Fixes: tag for commit 7e697ce99ceb and is marked for stable.

> A clk_prepare_enable(priv->phy_clk) call was specified within an if branch
> in the implementation of the function “bcm_enet_probe” while
> a clk_disable_unprepare(priv->phy_clk) call was unconditionally performed
> in the implementation of the function “bcm_enet_remove”.
> Move this clk_disable_unprepare() call into a corresponding if branch.
>
> Fixes: 7e697ce99ceb09538cdc1dfa9ebb3db60236b0a7 ("bcm63xx_enet: use managed functions for clock/ioremap")
> Cc: stable@vger.kernel.org

[Severity: Medium]
Is the unconditional call actually unbalanced?

bcm_enet_probe() only sets priv->phy_clk inside the branch that also
enables it. If devm_clk_get() fails, it resets the pointer to NULL:

	if (priv->has_phy && !priv->use_external_mii) {
		/* using internal PHY, enable clock */
		priv->phy_clk = devm_clk_get(&pdev->dev, "ephy");
		if (IS_ERR(priv->phy_clk)) {
			ret = PTR_ERR(priv->phy_clk);
			priv->phy_clk = NULL;
			goto out_disable_clk_mac;
		}
		ret = clk_prepare_enable(priv->phy_clk);
		...
	}

In every other case phy_clk stays NULL, because the netdev priv area is
zero-allocated.

BCM63XX_ENET depends on BCM63XX, which uses the legacy clock code in
arch/mips/bcm63xx/clk.c. Its clk_disable() returns early for NULL:

arch/mips/bcm63xx/clk.c:clk_disable() {
	if (!clk)
		return;
	...
}

clk_unprepare() is the inline stub in include/linux/clk.h, and it only
calls might_sleep(). So the old unconditional call did nothing whenever
the clock had not been enabled.

This looks intentional. Commit 4e78e5c5d881 ("bcm63xx_enet: drop unneeded
NULL phy_clk check") removed the earlier guard because "clk_disable and
clk_unprepare are NULL-safe".

The Fixes: target also doesn't seem to match. After 7e697ce99ceb,
bcm_enet_remove() still had the guard:

	if (priv->phy_clk)
		clk_disable_unprepare(priv->phy_clk);

Nothing changes after the later patch in the series ("bcm63xx_enet: Use
devm_clk_get_enabled() in two probe functions") either.

This patch doesn't change runtime behavior. Should the Fixes: and Cc:
stable tags be dropped, and the change described as a cleanup instead of
a fix?

> diff --git a/drivers/net/ethernet/broadcom/bcm63xx_enet.c b/drivers/net/ethernet/broadcom/bcm63xx_enet.c
> index f6595fdc888d1..cc9a5cd2a2a3f 100644
> --- a/drivers/net/ethernet/broadcom/bcm63xx_enet.c
> +++ b/drivers/net/ethernet/broadcom/bcm63xx_enet.c
> @@ -1915,6 +1915,9 @@ static void bcm_enet_remove(struct platform_device *pdev)
>  	enet_writel(priv, 0, ENET_MIISC_REG);
>  
>  	if (priv->has_phy) {
> +		if (!priv->use_external_mii)
> +			clk_disable_unprepare(priv->phy_clk);
> +
>  		mdiobus_unregister(priv->mii_bus);
>  		mdiobus_free(priv->mii_bus);

[Severity: Low]
Was it intended to move the EPHY clock disable ahead of
mdiobus_unregister() and mdiobus_free()?

Probe enables mac_clk, then phy_clk, and then registers the MDIO bus.
The probe error path in bcm_enet_probe() still undoes these in reverse
order:

out_unregister_mdio:
	if (priv->mii_bus)
		mdiobus_unregister(priv->mii_bus);

out_free_mdio:
	if (priv->mii_bus)
		mdiobus_free(priv->mii_bus);

out_uninit_hw:
	/* turn off mdc clock */
	enet_writel(priv, 0, ENET_MIISC_REG);
	clk_disable_unprepare(priv->phy_clk);

I couldn't find a concrete failure caused by the reorder:

- unregister_netdev() has already disconnected the PHY in ndo_stop.
- MDC is already turned off.
- The bcm63xx internal PHY driver has no .remove callback, so
  mdiobus_unregister() does no MDIO access here.

Still, disabling the clock after the MDIO teardown would keep remove()
as the exact reverse of probe.

> @@ -1927,7 +1930,6 @@ static void bcm_enet_remove(struct platform_device *pdev)
>  	}
>  
>  	/* disable hw block clocks */
> -	clk_disable_unprepare(priv->phy_clk);
>  	clk_disable_unprepare(priv->mac_clk);

[Severity: Low]
If the unconditional call here were a problem, wouldn't the same apply to
the out_uninit_hw label in bcm_enet_probe()? This patch leaves it
unchanged:

out_uninit_hw:
	/* turn off mdc clock */
	enet_writel(priv, 0, ENET_MIISC_REG);
	clk_disable_unprepare(priv->phy_clk);

That label can be reached without phy_clk ever being enabled:

- has_phy == 0 and pd->mii_config() fails.
- An external PHY is used and mdiobus_alloc(), mdiobus_register() or
  register_netdev() fails.

Both calls are NULL-safe, so this has no functional effect. But the two
teardown sites for the same clock now follow different conventions, and
the later devm_clk_get_enabled() patch keeps the unconditional call in
out_uninit_hw.

Should the remove-side change be dropped, or should both sites be
handled the same way?

>  
>  	free_netdev(dev);

[Severity: High]
This is a pre-existing issue, but it is in the same probe/remove pair.
In bcm_enet_probe(), when has_phy == 0 and pd->mii_config(dev, 1, ...)
fails:

		if (pd && pd->mii_config &&
		    pd->mii_config(dev, 1, bcm_enet_mdio_read_mii,
				   bcm_enet_mdio_write_mii)) {
			dev_err(&pdev->dev, "unable to configure mdio bus\n");
			goto out_uninit_hw;
		}

ret is not set on this path. Its last value came from
clk_prepare_enable(priv->mac_clk), which is 0. After the later patch in
the series it comes from bcm_enet_change_mtu(), also 0. So probe calls
free_netdev() and returns 0 without ever calling platform_set_drvdata().

On unbind or module removal, bcm_enet_remove() then runs with
dev == NULL:

	dev = platform_get_drvdata(pdev);
	priv = netdev_priv(dev);
	unregister_netdev(dev);

Can this oops in unregister_netdev(NULL)->rtnl_net_dev_lock()->dev_net()?

No in-tree board file sets mii_config, so this path needs out-of-tree
platform code.

Should ret be set to the return value of mii_config(), or to a negative
errno, before the goto?

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/0302adc3-dbf2-4e62-ac9b-8923ac285506%40web.de

  parent reply	other threads:[~2026-11-28 14:31 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-27 14:01 [PATCH v2 2/2] bcm63xx_enet: Adjustments for clock management Markus Elfring
2026-11-27 14:03 ` [PATCH net v2 1/2] bcm63xx_enet: Prevent unbalanced clk_disable_unprepare() call in bcm_enet_remove() Markus Elfring
2026-11-27 14:14   ` netdev-bot+sinfo
2026-11-27 14:26   ` Jonas Gorski
2026-11-27 14:33     ` [v2 " Markus Elfring
2026-11-28 14:31   ` netdev-bot+sashiko [this message]
2026-11-27 14:07 ` [PATCH net v2 2/2] bcm63xx_enet: Use devm_clk_get_enabled() in two probe functions Markus Elfring

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=179587631846.3135.16815258842003970286@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=Frank.Li@kernel.org \
    --cc=Julia.Lawall@inria.fr \
    --cc=Markus.Elfring@web.de \
    --cc=andrew+netdev@lunn.ch \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=christophe.jaillet@wanadoo.fr \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=f.fainelli@gmail.com \
    --cc=hemanth.selam@gmail.com \
    --cc=horms@kernel.org \
    --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=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