mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: wanghr2026@mail.zgclab.edu.cn
Cc: chester.a.unal@arinc9.com, daniel@makrotopia.org, andrew@lunn.ch,
	olteanv@gmail.com, davem@davemloft.net, edumazet@kernel.org,
	kuba@kernel.org, pabeni@redhat.com, matthias.bgg@gmail.com,
	angelogioacchino.delregno@collabora.com, netdev@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH net 1/5] net: dsa: mt7530: disable regulators on switch teardown
Date: Wed, 25 Nov 2026 09:27:14 +0000	[thread overview]
Message-ID: <179559883437.3135.6979042989700533423@kernel.org> (raw)
In-Reply-To: <179550875789.4156.10993765506582806373@mail.zgclab.edu.cn>

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

Critical: 0 · High: 0 · Medium: 1 · 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).

- [Medium] mt753x_teardown() now switches off the MT7530 core and IO
  supplies, but setup registered several interfaces with devm on…
- [Low] The commit message understates and partly mischaracterizes what
  the patch changes.

--

net: dsa: mt7530: disable regulators on switch teardown

This patch moves the MT7530 core and io regulator disable from
mt7530_remove() into mt753x_teardown(), after the stats polling work is
cancelled. The aim is to balance the enable in mt7530_setup() for switches
that are torn down without the driver reaching remove().

> Move the regulator disable from mt7530_remove() to mt753x_teardown(),
> after the stats polling work is cancelled so that no poll can run against
> an unpowered switch. This is a plain code movement, with the error
> reporting kept for now and cleaned up in a later patch.
>
> A switch in a multi-switch tree whose sibling fails to set up is torn
> down without its driver reaching remove(), so its regulators were left
> enabled until now.

[Severity: Low]
Is "a plain code movement" accurate? The patch seems to change more than
the message says.

On the remove path, the old mt7530_remove() disabled the supplies before
mt7530_remove_common()->dsa_unregister_switch(). The whole DSA teardown
therefore ran against an unpowered switch. With this patch, power is cut
last, from mt753x_teardown().

The leak can also happen with a single switch, not only in multi-switch
trees. dsa_switch_setup() calls ops->teardown on its error path when tag
protocol setup or user MII bus setup fails:

net/dsa/dsa.c:dsa_switch_setup() {
    ...
teardown:
	if (ds->ops->teardown)
		ds->ops->teardown(ds);
    ...
}

dsa_tree_setup() also tears down the switches when dsa_tree_setup_ports(),
dsa_tree_setup_conduit() or dsa_tree_setup_lags() fails.

In each of these cases probe fails and remove() never runs. The leaked
enable then triggers WARN_ON(regulator->enable_count) in _regulator_put()
when devres releases the regulator.

There is one more case. In a multi-switch tree that never finished setting
up, the old mt7530_remove() disabled regulators that had never been
enabled. That hit the regulator core's "unbalanced disables" warning, and
this patch fixes it as a side effect.

Could the commit message mention these cases and the change in ordering on
the remove path?

> diff --git a/drivers/net/dsa/mt7530.c b/drivers/net/dsa/mt7530.c
> index d5a199293f78a..c2f12ae2c6d7b 100644
> --- a/drivers/net/dsa/mt7530.c
> +++ b/drivers/net/dsa/mt7530.c
> @@ -3237,9 +3237,22 @@ static void
>  mt753x_teardown(struct dsa_switch *ds)
>  {
>  	struct mt7530_priv *priv = ds->priv;
> +	int ret;
>  
>  	if (priv->bus)
>  		cancel_delayed_work_sync(&priv->stats_work);
> +
> +	if (priv->id == ID_MT7530) {
> +		ret = regulator_disable(priv->core_pwr);
> +		if (ret < 0)
> +			dev_err(priv->dev,
> +				"Failed to disable core power: %d\n", ret);
> +
> +		ret = regulator_disable(priv->io_pwr);
> +		if (ret < 0)
> +			dev_err(priv->dev, "Failed to disable io pwr: %d\n",
> +				ret);
> +	}
>  }

[Severity: Medium]
After this, the switch has no power but is still bound. What happens to the
interfaces that setup registered with devm on priv->dev?

mt7530_setup_irq():
	ret = devm_regmap_add_irq_chip_fwnode(dev, dev_fwnode(dev),
					      priv->regmap, irq,
					      IRQF_ONESHOT,
					      0, &mt7530_regmap_irq_chip,
					      &irq_data);

mt7530_setup_mdio():
	ret = devm_of_mdiobus_register(dev, bus, mnp);

mt7530_setup_gpio():
	return devm_gpiochip_add_data(dev, gc, priv);

Neither mt753x_teardown() nor the DSA core undoes these, so they stay live
until the driver unbinds.

Take the case this commit targets: an MT7530 in a multi-switch tree whose
sibling fails setup. It goes through

dsa_tree_setup_switches()->dsa_tree_teardown_switches()->mt753x_teardown()

and stays bound with power off.

GPIO consumers such as gpio-leds on the switch LED pins would keep calling
mt7530_gpio_set() and mt7530_gpio_get(). regmap reports success, but the
writes are lost and the reads return garbage.

The parent IRQ also stays requested. If the line asserts while the switch
has no power, regmap_irq_thread() would run against dead hardware. Every
nested source is masked, so it returns IRQ_NONE. That repeats until
spurious interrupt detection disables the line.

Before this patch the rails stayed on in this case. On the normal remove()
path the patch actually makes the unpowered window shorter.

The root cause is older: devm registrations in ->setup outlive ->teardown.
The later patch "disable regulators on mt753x_setup() failure" has the same
pattern. It powers off after a mt7530_setup_mdio() or create_sgmii()
failure, while the devm IRQ chip and MDIO bus are still registered.

Should teardown also unregister these interfaces? Or should the regulators
stay enabled until remove()?

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/179550875789.4156.361477684651496992%40mail.zgclab.edu.cn

  parent reply	other threads:[~2026-11-25  9:27 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-24  8:25 [PATCH net 0/5] net: dsa: mt7530: fix regulator disable on teardown and error paths Haoran Wang
2026-11-24  8:25 ` [PATCH net 2/5] net: dsa: mt7530: factor out mt7530_disable_pwrs() Haoran Wang
2026-11-24 18:35   ` Andrew Lunn
2026-11-24  8:25 ` [PATCH net 1/5] net: dsa: mt7530: disable regulators on switch teardown Haoran Wang
2026-11-24 18:31   ` Andrew Lunn
2026-11-25  9:27   ` netdev-bot+sashiko [this message]
2026-11-24  8:25 ` [PATCH net 3/5] net: dsa: mt7530: register the GPIO controller last in setup Haoran Wang
2026-11-24 18:38   ` Andrew Lunn
2026-11-25  9:27   ` netdev-bot+sashiko
2026-11-24  8:25 ` [PATCH net 4/5] net: dsa: mt7530: disable regulators on setup failure Haoran Wang
2026-11-24 18:42   ` Andrew Lunn
2026-11-24  8:25 ` [PATCH net 5/5] net: dsa: mt7530: disable regulators on mt753x_setup() failure Haoran Wang
2026-11-24 18:50   ` Andrew Lunn
2026-11-25  9:27   ` netdev-bot+sashiko
2026-11-24  8:33 ` [PATCH net 0/5] net: dsa: mt7530: fix regulator disable on teardown and error paths netdev-bot+sinfo

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=179559883437.3135.6979042989700533423@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=andrew@lunn.ch \
    --cc=angelogioacchino.delregno@collabora.com \
    --cc=chester.a.unal@arinc9.com \
    --cc=daniel@makrotopia.org \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=matthias.bgg@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=olteanv@gmail.com \
    --cc=pabeni@redhat.com \
    --cc=wanghr2026@mail.zgclab.edu.cn \
    /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

all inboxes | Powered by JetHome®