* [PATCH net 2/5] net: dsa: mt7530: factor out mt7530_disable_pwrs()
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 ` 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
` (4 subsequent siblings)
5 siblings, 1 reply; 15+ messages in thread
From: Haoran Wang @ 2026-11-24 8:25 UTC (permalink / raw)
To: chester.a.unal, daniel, andrew, olteanv
Cc: davem, edumazet, kuba, pabeni, matthias.bgg,
angelogioacchino.delregno, netdev, linux-arm-kernel,
linux-mediatek, linux-kernel
Pull the regulator disable out of mt753x_teardown() into a helper so it
can also be used on the setup error paths added in later patches.
The helper stops reporting regulator_disable() failures. A failed
disable on a teardown or error path is not actionable, and on the error
paths the failure being handled is already reported, so the extra
messages would only add noise.
Signed-off-by: Haoran Wang <wanghr2026@mail.zgclab.edu.cn>
---
drivers/net/dsa/mt7530.c | 23 +++++++++++------------
1 file changed, 11 insertions(+), 12 deletions(-)
diff --git a/drivers/net/dsa/mt7530.c b/drivers/net/dsa/mt7530.c
index c2f12ae2c6d7..eb55cc969f43 100644
--- a/drivers/net/dsa/mt7530.c
+++ b/drivers/net/dsa/mt7530.c
@@ -2376,6 +2376,16 @@ mt7530_setup_mdio(struct mt7530_priv *priv)
return ret;
}
+static void
+mt7530_disable_pwrs(struct mt7530_priv *priv)
+{
+ if (priv->id != ID_MT7530)
+ return;
+
+ regulator_disable(priv->core_pwr);
+ regulator_disable(priv->io_pwr);
+}
+
static int
mt7530_setup(struct dsa_switch *ds)
{
@@ -3237,22 +3247,11 @@ 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);
- }
+ mt7530_disable_pwrs(priv);
}
static int mt753x_set_mac_eee(struct dsa_switch *ds, int port,
^ permalink raw reply [flat|nested] 15+ messages in thread* Re: [PATCH net 2/5] net: dsa: mt7530: factor out mt7530_disable_pwrs()
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
0 siblings, 0 replies; 15+ messages in thread
From: Andrew Lunn @ 2026-11-24 18:35 UTC (permalink / raw)
To: Haoran Wang
Cc: chester.a.unal, daniel, olteanv, davem, edumazet, kuba, pabeni,
matthias.bgg, angelogioacchino.delregno, netdev,
linux-arm-kernel, linux-mediatek, linux-kernel
On Tue, Nov 24, 2026 at 04:25:57PM +0800, Haoran Wang wrote:
> Pull the regulator disable out of mt753x_teardown() into a helper so it
> can also be used on the setup error paths added in later patches.
>
> The helper stops reporting regulator_disable() failures. A failed
> disable on a teardown or error path is not actionable
While i agree there is no need to add code to try to recover from the
failed disabling, if the disable does fail, something is wrong
somewhere. So we want to know about it, so it can be investigated.
I would keep the error messages.
Andrew
^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH net 1/5] net: dsa: mt7530: disable regulators on switch teardown
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 8:25 ` Haoran Wang
2026-11-24 18:31 ` Andrew Lunn
2026-11-25 9:27 ` netdev-bot+sashiko
2026-11-24 8:25 ` [PATCH net 3/5] net: dsa: mt7530: register the GPIO controller last in setup Haoran Wang
` (3 subsequent siblings)
5 siblings, 2 replies; 15+ messages in thread
From: Haoran Wang @ 2026-11-24 8:25 UTC (permalink / raw)
To: chester.a.unal, daniel, andrew, olteanv
Cc: davem, edumazet, kuba, pabeni, matthias.bgg,
angelogioacchino.delregno, netdev, linux-arm-kernel,
linux-mediatek, linux-kernel
mt7530_setup() enables the core and io regulators, so they should be
disabled by the matching teardown callback, not by the driver remove
callback. teardown is the counterpart of setup and runs for every switch
that was successfully set up, whereas remove() only runs when the whole
driver is unbound.
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.
Fixes: b8f126a8d543 ("net-next: dsa: add dsa support for Mediatek MT7530 switch")
Signed-off-by: Haoran Wang <wanghr2026@mail.zgclab.edu.cn>
---
drivers/net/dsa/mt7530-mdio.c | 14 +-------------
drivers/net/dsa/mt7530.c | 13 +++++++++++++
2 files changed, 14 insertions(+), 13 deletions(-)
diff --git a/drivers/net/dsa/mt7530-mdio.c b/drivers/net/dsa/mt7530-mdio.c
index e85ef2aceee5..faefbcad293f 100644
--- a/drivers/net/dsa/mt7530-mdio.c
+++ b/drivers/net/dsa/mt7530-mdio.c
@@ -227,23 +227,11 @@ static void
mt7530_remove(struct mdio_device *mdiodev)
{
struct mt7530_priv *priv = dev_get_drvdata(&mdiodev->dev);
- int ret = 0, i;
+ int i;
if (!priv)
return;
- 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);
- }
-
mt7530_remove_common(priv);
for (i = 0; i < 2; ++i)
diff --git a/drivers/net/dsa/mt7530.c b/drivers/net/dsa/mt7530.c
index d5a199293f78..c2f12ae2c6d7 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);
+ }
}
static int mt753x_set_mac_eee(struct dsa_switch *ds, int port,
^ permalink raw reply [flat|nested] 15+ messages in thread* Re: [PATCH net 1/5] net: dsa: mt7530: disable regulators on switch teardown
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
1 sibling, 0 replies; 15+ messages in thread
From: Andrew Lunn @ 2026-11-24 18:31 UTC (permalink / raw)
To: Haoran Wang
Cc: chester.a.unal, daniel, olteanv, davem, edumazet, kuba, pabeni,
matthias.bgg, angelogioacchino.delregno, netdev,
linux-arm-kernel, linux-mediatek, linux-kernel
Thanks for breaking up the patch.
> Fixes: b8f126a8d543 ("net-next: dsa: add dsa support for Mediatek MT7530 switch")
> Signed-off-by: Haoran Wang <wanghr2026@mail.zgclab.edu.cn>
Do these issues actually bother anybody. If not, net-next, not net.
When you repost, please add my Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Andrew
---
pw-bot: cr
^ permalink raw reply [flat|nested] 15+ messages in thread* Re: [PATCH net 1/5] net: dsa: mt7530: disable regulators on switch teardown
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
1 sibling, 0 replies; 15+ messages in thread
From: netdev-bot+sashiko @ 2026-11-25 9:27 UTC (permalink / raw)
To: wanghr2026
Cc: chester.a.unal, daniel, andrew, olteanv, davem, edumazet, kuba,
pabeni, matthias.bgg, angelogioacchino.delregno, netdev,
linux-arm-kernel, linux-mediatek, linux-kernel
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
^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH net 3/5] net: dsa: mt7530: register the GPIO controller last in setup
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 8:25 ` [PATCH net 1/5] net: dsa: mt7530: disable regulators on switch teardown Haoran Wang
@ 2026-11-24 8:25 ` Haoran Wang
2026-11-24 18:38 ` Andrew Lunn
2026-11-25 9:27 ` netdev-bot+sashiko
2026-11-24 8:25 ` [PATCH net 5/5] net: dsa: mt7530: disable regulators on mt753x_setup() failure Haoran Wang
` (2 subsequent siblings)
5 siblings, 2 replies; 15+ messages in thread
From: Haoran Wang @ 2026-11-24 8:25 UTC (permalink / raw)
To: chester.a.unal, daniel, andrew, olteanv
Cc: davem, edumazet, kuba, pabeni, matthias.bgg,
angelogioacchino.delregno, netdev, linux-arm-kernel,
linux-mediatek, linux-kernel
mt7530_setup_gpio() publishes a GPIO controller that userspace and other
drivers can use immediately, but it currently runs before the FDB flush,
which is the last step of setup that can fail.
Move the GPIO controller registration after the FDB flush so that the
controller is only made visible once every fallible step, including the
FDB flush, has succeeded. This becomes important in the next patch, where
the failure paths disable the regulators and return an error, so the
controller must not be registered across a failed setup.
Signed-off-by: Haoran Wang <wanghr2026@mail.zgclab.edu.cn>
---
drivers/net/dsa/mt7530.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/drivers/net/dsa/mt7530.c b/drivers/net/dsa/mt7530.c
index eb55cc969f43..e208d942b577 100644
--- a/drivers/net/dsa/mt7530.c
+++ b/drivers/net/dsa/mt7530.c
@@ -2585,6 +2585,11 @@ mt7530_setup(struct dsa_switch *ds)
}
}
+ /* Flush the FDB table */
+ ret = mt7530_fdb_cmd(priv, MT7530_FDB_FLUSH, NULL);
+ if (ret < 0)
+ return ret;
+
#ifdef CONFIG_GPIOLIB
if (of_property_read_bool(priv->dev->of_node, "gpio-controller")) {
ret = mt7530_setup_gpio(priv);
@@ -2593,11 +2598,6 @@ mt7530_setup(struct dsa_switch *ds)
}
#endif /* CONFIG_GPIOLIB */
- /* Flush the FDB table */
- ret = mt7530_fdb_cmd(priv, MT7530_FDB_FLUSH, NULL);
- if (ret < 0)
- return ret;
-
return 0;
}
^ permalink raw reply [flat|nested] 15+ messages in thread* Re: [PATCH net 3/5] net: dsa: mt7530: register the GPIO controller last in setup
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
1 sibling, 0 replies; 15+ messages in thread
From: Andrew Lunn @ 2026-11-24 18:38 UTC (permalink / raw)
To: Haoran Wang
Cc: chester.a.unal, daniel, olteanv, davem, edumazet, kuba, pabeni,
matthias.bgg, angelogioacchino.delregno, netdev,
linux-arm-kernel, linux-mediatek, linux-kernel
On Tue, Nov 24, 2026 at 04:25:57PM +0800, Haoran Wang wrote:
> mt7530_setup_gpio() publishes a GPIO controller that userspace and other
> drivers can use immediately, but it currently runs before the FDB flush,
> which is the last step of setup that can fail.
>
> Move the GPIO controller registration after the FDB flush so that the
> controller is only made visible once every fallible step, including the
> FDB flush, has succeeded. This becomes important in the next patch, where
> the failure paths disable the regulators and return an error, so the
> controller must not be registered across a failed setup.
>
> Signed-off-by: Haoran Wang <wanghr2026@mail.zgclab.edu.cn>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Andrew
^ permalink raw reply [flat|nested] 15+ messages in thread* Re: [PATCH net 3/5] net: dsa: mt7530: register the GPIO controller last in setup
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
1 sibling, 0 replies; 15+ messages in thread
From: netdev-bot+sashiko @ 2026-11-25 9:27 UTC (permalink / raw)
To: wanghr2026
Cc: chester.a.unal, daniel, andrew, olteanv, davem, edumazet, kuba,
pabeni, matthias.bgg, angelogioacchino.delregno, netdev,
linux-arm-kernel, linux-mediatek, linux-kernel
Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 0
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] net: dsa: mt7530: mt7530_setup_gpio() still runs before
fallible setup steps
--
> diff --git a/drivers/net/dsa/mt7530.c b/drivers/net/dsa/mt7530.c
> --- a/drivers/net/dsa/mt7530.c
> +++ b/drivers/net/dsa/mt7530.c
> @@ -2585,6 +2585,11 @@ mt7530_setup(struct dsa_switch *ds)
> }
> }
>
> + /* Flush the FDB table */
> + ret = mt7530_fdb_cmd(priv, MT7530_FDB_FLUSH, NULL);
> + if (ret < 0)
> + return ret;
> +
> #ifdef CONFIG_GPIOLIB
> if (of_property_read_bool(priv->dev->of_node, "gpio-controller")) {
> ret = mt7530_setup_gpio(priv);
[Severity: Medium]
The commit message says this makes the GPIO controller visible only
once every fallible step of setup has succeeded. However, mt7530_setup()
is only the priv->info->sw_setup() callback. After it returns 0,
mt753x_setup() still calls mt7530_setup_irq() and mt7530_setup_mdio().
Both of those can fail, and mt7530_setup_irq() can also return
-EPROBE_DEFER.
If either of them fails, the gpio_chip that mt7530_setup_gpio()
registered with devm_gpiochip_add_data() on priv->dev stays published.
Once the next patch disables core_pwr and io_pwr on the failure path,
consumers would be left poking MT7530_LED_GPIO_* registers on an
unpowered switch. That is the situation this patch says it prevents.
The same applies to teardown. The chip is tied to devres on priv->dev,
not to the DSA setup/teardown cycle. Consider a multi-switch tree where
a sibling switch fails or defers. mt753x_teardown() then disables the
regulators without unbinding priv->dev, so the chip remains registered.
The next dsa_tree_setup() attempt would run mt7530_setup_gpio() again
and add a second controller.
Should the GPIO registration move to the end of mt753x_setup(), after
mt7530_setup_mdio(), with an explicit gpiochip_remove() in the error
path and in mt753x_teardown()? Or would you rather register it from
probe instead? Either way, the commit message should not claim it is
the last fallible step as things stand.
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/179550875789.4156.361477684651496992%40mail.zgclab.edu.cn
^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH net 5/5] net: dsa: mt7530: disable regulators on mt753x_setup() failure
2026-11-24 8:25 [PATCH net 0/5] net: dsa: mt7530: fix regulator disable on teardown and error paths Haoran Wang
` (2 preceding siblings ...)
2026-11-24 8:25 ` [PATCH net 3/5] net: dsa: mt7530: register the GPIO controller last in setup Haoran Wang
@ 2026-11-24 8:25 ` Haoran Wang
2026-11-24 18:50 ` 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 8:33 ` [PATCH net 0/5] net: dsa: mt7530: fix regulator disable on teardown and error paths netdev-bot+sinfo
5 siblings, 2 replies; 15+ messages in thread
From: Haoran Wang @ 2026-11-24 8:25 UTC (permalink / raw)
To: chester.a.unal, daniel, andrew, olteanv
Cc: davem, edumazet, kuba, pabeni, matthias.bgg,
angelogioacchino.delregno, netdev, linux-arm-kernel,
linux-mediatek, linux-kernel
mt753x_setup() calls the per-variant sw_setup() (mt7530_setup() for the
MT7530), which enables the regulators, but the steps that follow returned
on error without disabling them. The common case is mt7530_setup_irq()
returning -EPROBE_DEFER, which leaves the rails on and re-enables them on
every re-probe.
Route all failure paths after sw_setup() to a shared error label that
disables the regulators, and move the mdio irq teardown there instead of
handling it inline.
Fixes: b8f126a8d543 ("net-next: dsa: add dsa support for Mediatek MT7530 switch")
Signed-off-by: Haoran Wang <wanghr2026@mail.zgclab.edu.cn>
---
drivers/net/dsa/mt7530.c | 18 +++++++++++++-----
1 file changed, 13 insertions(+), 5 deletions(-)
diff --git a/drivers/net/dsa/mt7530.c b/drivers/net/dsa/mt7530.c
index 1ac4ac1a0566..963d14534175 100644
--- a/drivers/net/dsa/mt7530.c
+++ b/drivers/net/dsa/mt7530.c
@@ -3223,11 +3223,11 @@ mt753x_setup(struct dsa_switch *ds)
ret = mt7530_setup_irq(priv);
if (ret)
- return ret;
+ goto err_disable_pwrs;
ret = mt7530_setup_mdio(priv);
if (ret)
- return ret;
+ goto err_disable_pwrs;
/* Initialise the PCS devices */
for (i = 0; i < priv->ds->num_ports; i++) {
@@ -3239,15 +3239,23 @@ mt753x_setup(struct dsa_switch *ds)
if (priv->create_sgmii)
ret = priv->create_sgmii(priv);
- if (ret && priv->irq_domain)
- mt7530_free_mdio_irq(priv);
+ if (ret)
+ goto err_free_irq;
- if (!ret && priv->bus) {
+ if (priv->bus) {
mt7530_stats_refresh(priv);
schedule_delayed_work(&priv->stats_work,
MT7530_STATS_POLL_INTERVAL);
}
+ return 0;
+
+err_free_irq:
+ if (priv->irq_domain)
+ mt7530_free_mdio_irq(priv);
+err_disable_pwrs:
+ mt7530_disable_pwrs(priv);
+
return ret;
}
^ permalink raw reply [flat|nested] 15+ messages in thread* Re: [PATCH net 5/5] net: dsa: mt7530: disable regulators on mt753x_setup() failure
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
1 sibling, 0 replies; 15+ messages in thread
From: Andrew Lunn @ 2026-11-24 18:50 UTC (permalink / raw)
To: Haoran Wang
Cc: chester.a.unal, daniel, olteanv, davem, edumazet, kuba, pabeni,
matthias.bgg, angelogioacchino.delregno, netdev,
linux-arm-kernel, linux-mediatek, linux-kernel
On Tue, Nov 24, 2026 at 04:25:57PM +0800, Haoran Wang wrote:
> mt753x_setup() calls the per-variant sw_setup() (mt7530_setup() for the
> MT7530), which enables the regulators, but the steps that follow returned
> on error without disabling them. The common case is mt7530_setup_irq()
> returning -EPROBE_DEFER, which leaves the rails on and re-enables them on
> every re-probe.
>
> Route all failure paths after sw_setup() to a shared error label that
> disables the regulators, and move the mdio irq teardown there instead of
> handling it inline.
From an architecture side, this is not great. We have a per-variant
sw_setup() function. To keep things symmetric, there should be a
per-variant sw_teardown() function.
Andrew
^ permalink raw reply [flat|nested] 15+ messages in thread* Re: [PATCH net 5/5] net: dsa: mt7530: disable regulators on mt753x_setup() failure
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
1 sibling, 0 replies; 15+ messages in thread
From: netdev-bot+sashiko @ 2026-11-25 9:27 UTC (permalink / raw)
To: wanghr2026
Cc: chester.a.unal, daniel, andrew, olteanv, davem, edumazet, kuba,
pabeni, matthias.bgg, angelogioacchino.delregno, netdev,
linux-arm-kernel, linux-mediatek, linux-kernel
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.
Critical: 0 · High: 1 (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] In mt753x_setup() (drivers/net/dsa/mt7530.c), the new error
paths turn off the MT7530 core/io regulators while devm still keeps…
- [Low] net: dsa: mt7530: inaccurate Fixes tag for mt753x_setup()
regulator leak
Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but it sits on the
failure path the patch reworks.
--
net: dsa: mt7530: disable regulators on mt753x_setup() failure
This patch sends the failure paths in mt753x_setup() that come after
sw_setup() to a shared error label. That label disables the MT7530 core
and io regulators. The mdio irq teardown after a create_sgmii() failure
moves into the same error path.
> diff --git a/drivers/net/dsa/mt7530.c b/drivers/net/dsa/mt7530.c
> index 1ac4ac1a05664..963d145341759 100644
> --- a/drivers/net/dsa/mt7530.c
> +++ b/drivers/net/dsa/mt7530.c
> @@ -3223,11 +3223,11 @@ mt753x_setup(struct dsa_switch *ds)
>
> ret = mt7530_setup_irq(priv);
> if (ret)
> - return ret;
> + goto err_disable_pwrs;
>
> ret = mt7530_setup_mdio(priv);
> if (ret)
> - return ret;
> + goto err_disable_pwrs;
[Severity: Low]
Is b8f126a8d543 the right commit for the Fixes tag?
In b8f126a8d543, mt7530_switch_ops.setup pointed straight at
mt7530_setup(). There was no mt753x_setup() wrapper and nothing ran
after sw_setup(). The wrapper came with 88bdef8be9f6 ("net: dsa:
mt7530: Extend device data ready for adding a new hardware"), and
at that point it only did:
return priv->info->sw_setup(ds);
This patch now unwinds the fallible steps after sw_setup(), which are
mt7530_setup_irq() and mt7530_setup_mdio(). Those steps seem to have
come in with ba751e28d442 ("net: dsa: mt7530: add interrupt support").
That commit is where the early returns that leave the regulators on
were added.
With the Fixes tag pointing at the initial driver, the stable tooling
will try to apply this to kernels that have neither mt753x_setup() nor
these failure paths. Should the tag be this instead?
Fixes: ba751e28d442 ("net: dsa: mt7530: add interrupt support")
[Severity: High]
Can these new gotos power off the switch while things that need power
are still registered?
When mt753x_setup() reaches this point, mt7530_setup() has already
returned 0. If the DT node has "gpio-controller", the GPIO controller is
already published:
mt7530_setup()
mt7530_setup_gpio()
return devm_gpiochip_add_data(dev, gc, priv);
Suppose mt7530_setup_irq() then fails, for example with -EPROBE_DEFER
from of_irq_get(). The commit message calls this the common case. In
that case mt7530_disable_pwrs() turns off the rails and the gpiochip
stays registered.
If mt7530_setup_mdio() fails instead, the regmap-irq chip from
devm_regmap_add_irq_chip_fwnode() in mt7530_setup_irq() also stays
registered. Its parent IRQ stays requested and TOP_SIG_CTRL_NORMAL stays
set.
Nothing on these paths unregisters them. Only devres unwinding removes
them:
- With a single switch, devres unwinds after dsa_register_switch() fails
and probe returns.
- In a multi-switch tree, this switch's probe may already have returned
0 and the tree setup runs from a sibling's probe. Then devres never
unwinds here, and the switch stays bound against unpowered hardware.
The earlier patch in this series, "net: dsa: mt7530: register the GPIO
controller last in setup", says:
This becomes important in the next patch, where
the failure paths disable the regulators and return an error, so the
controller must not be registered across a failed setup.
Doesn't this patch make that state reachable again on the
mt7530_setup_irq() and mt7530_setup_mdio() failure paths? Only ID_MT7530
is affected, because mt7530_disable_pwrs() returns early for the other
variants.
Could the regulator-dependent registrations (the gpiochip, and ideally
the irq chip and MDIO bus) happen after every fallible step in
mt753x_setup()? Alternatively, could they be undone explicitly before
mt7530_disable_pwrs() is called?
[ ... ]
> @@ -3239,15 +3239,23 @@ mt753x_setup(struct dsa_switch *ds)
> if (priv->create_sgmii)
> ret = priv->create_sgmii(priv);
>
> - if (ret && priv->irq_domain)
> - mt7530_free_mdio_irq(priv);
> + if (ret)
> + goto err_free_irq;
[Severity: High]
This is a pre-existing issue, but it sits on the failure path this patch
reworks. Can a failed create_sgmii() leave priv->ports[5].sgmii_pcs
dangling, and then have it freed a second time?
Take mt7531_create_sgmii() in drivers/net/dsa/mt7530-mdio.c with
p5_sgmii set, where port5 succeeds and port6 fails:
if (ret && i)
mtk_pcs_lynxi_destroy(priv->ports[5].sgmii_pcs);
return ret;
This frees the port5 PCS but does not clear the pointer. Port6 can fail
in devm_kzalloc_obj(), in devm_regmap_init(), or when
mtk_pcs_lynxi_create() returns NULL.
With a single switch, probe fails and devres frees priv.
In a multi-switch tree, the MT7531 can register before the tree is
complete, so its probe returns 0. mt753x_setup() then runs later from a
sibling's probe via dsa_tree_setup()->dsa_switch_setup(). If
create_sgmii() fails there, the MT7531 stays bound with the stale
pointer. On a later unbind this runs:
mt7530_remove()
for (i = 0; i < 2; ++i)
mtk_pcs_lynxi_destroy(priv->ports[5 + i].sgmii_pcs);
Is the port5 PCS kfree()d a second time here? Setting
priv->ports[5].sgmii_pcs = NULL after the destroy in
mt7531_create_sgmii() would avoid it.
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/179550875789.4156.361477684651496992%40mail.zgclab.edu.cn
^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH net 4/5] net: dsa: mt7530: disable regulators on setup failure
2026-11-24 8:25 [PATCH net 0/5] net: dsa: mt7530: fix regulator disable on teardown and error paths Haoran Wang
` (3 preceding siblings ...)
2026-11-24 8:25 ` [PATCH net 5/5] net: dsa: mt7530: disable regulators on mt753x_setup() failure Haoran Wang
@ 2026-11-24 8:25 ` Haoran Wang
2026-11-24 18:42 ` Andrew Lunn
2026-11-24 8:33 ` [PATCH net 0/5] net: dsa: mt7530: fix regulator disable on teardown and error paths netdev-bot+sinfo
5 siblings, 1 reply; 15+ messages in thread
From: Haoran Wang @ 2026-11-24 8:25 UTC (permalink / raw)
To: chester.a.unal, daniel, andrew, olteanv
Cc: davem, edumazet, kuba, pabeni, matthias.bgg,
angelogioacchino.delregno, netdev, linux-arm-kernel,
linux-mediatek, linux-kernel
Once the core and io regulators have been enabled, every later failure
in mt7530_setup() returned without disabling them, leaving the rails
enabled and making the regulator core warn when devres later puts an
enabled regulator.
Route those failure paths to a common error label that disables both
regulators, and disable the already enabled core regulator if enabling
the io regulator fails.
Fixes: b8f126a8d543 ("net-next: dsa: add dsa support for Mediatek MT7530 switch")
Signed-off-by: Haoran Wang <wanghr2026@mail.zgclab.edu.cn>
---
drivers/net/dsa/mt7530.c | 22 +++++++++++++++-------
1 file changed, 15 insertions(+), 7 deletions(-)
diff --git a/drivers/net/dsa/mt7530.c b/drivers/net/dsa/mt7530.c
index e208d942b577..1ac4ac1a0566 100644
--- a/drivers/net/dsa/mt7530.c
+++ b/drivers/net/dsa/mt7530.c
@@ -2435,6 +2435,7 @@ mt7530_setup(struct dsa_switch *ds)
if (ret < 0) {
dev_err(priv->dev, "Failed to enable io pwr: %d\n",
ret);
+ regulator_disable(priv->core_pwr);
return ret;
}
}
@@ -2457,20 +2458,22 @@ mt7530_setup(struct dsa_switch *ds)
val != 0, 20, 1000000);
if (ret < 0) {
dev_err(priv->dev, "reset timeout\n");
- return ret;
+ goto err_disable_pwrs;
}
regmap_read(priv->regmap, MT7530_CREV, &id);
id = FIELD_GET(CHIP_NAME_MASK, id);
if (id != MT7530_ID) {
dev_err(priv->dev, "chip %x can't be supported\n", id);
- return -ENODEV;
+ ret = -ENODEV;
+ goto err_disable_pwrs;
}
if ((val & MT7530_XTAL_MASK) == MT7530_XTAL_20MHZ) {
dev_err(priv->dev,
"MT7530 with a 20MHz XTAL is not supported!\n");
- return -EINVAL;
+ ret = -EINVAL;
+ goto err_disable_pwrs;
}
/* Reset the switch through internal reset */
@@ -2537,7 +2540,7 @@ mt7530_setup(struct dsa_switch *ds)
/* Setup VLAN ID 0 for VLAN-unaware bridges */
ret = mt7530_setup_vlan0(priv);
if (ret)
- return ret;
+ goto err_disable_pwrs;
/* Check for PHY muxing on port 5 */
if (dsa_is_unused_port(ds, 5)) {
@@ -2564,7 +2567,7 @@ mt7530_setup(struct dsa_switch *ds)
if (ret && ret != -ENODEV) {
of_node_put(mac_np);
of_node_put(phy_node);
- return ret;
+ goto err_disable_pwrs;
}
id = of_mdio_parse_addr(ds->dev, phy_node);
if (id == 0)
@@ -2588,17 +2591,22 @@ mt7530_setup(struct dsa_switch *ds)
/* Flush the FDB table */
ret = mt7530_fdb_cmd(priv, MT7530_FDB_FLUSH, NULL);
if (ret < 0)
- return ret;
+ goto err_disable_pwrs;
#ifdef CONFIG_GPIOLIB
if (of_property_read_bool(priv->dev->of_node, "gpio-controller")) {
ret = mt7530_setup_gpio(priv);
if (ret)
- return ret;
+ goto err_disable_pwrs;
}
#endif /* CONFIG_GPIOLIB */
return 0;
+
+err_disable_pwrs:
+ mt7530_disable_pwrs(priv);
+
+ return ret;
}
static int
^ permalink raw reply [flat|nested] 15+ messages in thread* Re: [PATCH net 4/5] net: dsa: mt7530: disable regulators on setup failure
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
0 siblings, 0 replies; 15+ messages in thread
From: Andrew Lunn @ 2026-11-24 18:42 UTC (permalink / raw)
To: Haoran Wang
Cc: chester.a.unal, daniel, olteanv, davem, edumazet, kuba, pabeni,
matthias.bgg, angelogioacchino.delregno, netdev,
linux-arm-kernel, linux-mediatek, linux-kernel
On Tue, Nov 24, 2026 at 04:25:57PM +0800, Haoran Wang wrote:
> Once the core and io regulators have been enabled, every later failure
> in mt7530_setup() returned without disabling them, leaving the rails
> enabled and making the regulator core warn when devres later puts an
> enabled regulator.
>
> Route those failure paths to a common error label that disables both
> regulators, and disable the already enabled core regulator if enabling
> the io regulator fails.
>
> Fixes: b8f126a8d543 ("net-next: dsa: add dsa support for Mediatek MT7530 switch")
> Signed-off-by: Haoran Wang <wanghr2026@mail.zgclab.edu.cn>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Andrew
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH net 0/5] net: dsa: mt7530: fix regulator disable on teardown and error paths
2026-11-24 8:25 [PATCH net 0/5] net: dsa: mt7530: fix regulator disable on teardown and error paths Haoran Wang
` (4 preceding siblings ...)
2026-11-24 8:25 ` [PATCH net 4/5] net: dsa: mt7530: disable regulators on setup failure Haoran Wang
@ 2026-11-24 8:33 ` netdev-bot+sinfo
5 siblings, 0 replies; 15+ messages in thread
From: netdev-bot+sinfo @ 2026-11-24 8:33 UTC (permalink / raw)
To: Haoran Wang
Cc: chester.a.unal, daniel, andrew, olteanv, davem, edumazet, kuba,
pabeni, matthias.bgg, angelogioacchino.delregno, netdev,
linux-arm-kernel, linux-mediatek, linux-kernel
Hi!
This is an automated message. This series looks like a fix, but its
commit messages seem to be missing some information:
- How the issue was discovered, e.g. hit in production, hit during
development, syzbot report, manual code inspection, LLM or static
analysis tool scan.
- Whether the issue was actually triggered, or is only theoretical
(e.g. found by LLM and not proven at runtime). If it was triggered
please include the symptoms, like the stack trace or kernel messages.
Please do not repost the series just to address the above. Instead,
reply to this email with the missing information, so that reviewers
can take it into account.
*IMPORTANT*: If you do repost (for other reasons) - please include
the relevant info in the cover letter or commit messages.
--
The evaluation is done by an LLM so it may be wrong, if you think
that is the case please reply and explain.
^ permalink raw reply [flat|nested] 15+ messages in thread