* [PATCH net 0/5] net: dsa: mt7530: fix regulator disable on teardown and error paths
@ 2026-11-24 8:25 Haoran Wang
2026-11-24 8:25 ` [PATCH net 1/5] net: dsa: mt7530: disable regulators on switch teardown Haoran Wang
` (5 more replies)
0 siblings, 6 replies; 7+ 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, but they were not
always disabled again:
- the disable lived in the driver's remove() callback instead of the
matching teardown callback, so a switch whose sibling failed to set
up was torn down without reaching remove() and kept its regulators
enabled, and
- the error paths in mt7530_setup() and mt753x_setup() returned without
disabling the regulators, leaving the rails enabled and making the
regulator core warn when devres later put an enabled regulator. The
common case is mt7530_setup_irq() returning -EPROBE_DEFER, which
re-enabled the rails on every re-probe.
This series splits the original patch into five small, independently
obvious changes, as requested by Andrew Lunn:
1. Move the disable from remove() to teardown().
2. Factor the disable into mt7530_disable_pwrs().
3. Register the GPIO controller last so it is not published across a
failed setup.
4. Disable the regulators on every mt7530_setup() error path.
5. Do the same for mt753x_setup(), moving the mdio irq teardown to the
end.
Haoran Wang (5):
net: dsa: mt7530: disable regulators on switch teardown
net: dsa: mt7530: factor out mt7530_disable_pwrs()
net: dsa: mt7530: register the GPIO controller last in setup
net: dsa: mt7530: disable regulators on setup failure
net: dsa: mt7530: disable regulators on mt753x_setup() failure
drivers/net/dsa/mt7530-mdio.c | 14 +-------
drivers/net/dsa/mt7530.c | 60 +++++++++++++++++++++++++----------
2 files changed, 45 insertions(+), 29 deletions(-)
^ permalink raw reply [flat|nested] 7+ messages in thread
* [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 ` [PATCH net 1/5] net: dsa: mt7530: disable regulators on switch teardown Haoran Wang
@ 2026-11-24 8:25 ` Haoran Wang
2026-11-24 8:25 ` [PATCH net 5/5] net: dsa: mt7530: disable regulators on mt753x_setup() failure Haoran Wang
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ 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 related [flat|nested] 7+ 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
` (3 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:25 ` 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, 0 replies; 7+ 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 related [flat|nested] 7+ 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
` (2 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 8:25 ` [PATCH net 3/5] net: dsa: mt7530: register the GPIO controller last in setup 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, 0 replies; 7+ 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 related [flat|nested] 7+ 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 ` Haoran Wang
2026-11-24 8:25 ` [PATCH net 2/5] net: dsa: mt7530: factor out mt7530_disable_pwrs() Haoran Wang
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ 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 related [flat|nested] 7+ 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
2026-11-24 8:25 ` [PATCH net 1/5] net: dsa: mt7530: disable regulators on switch teardown 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 8:25 ` [PATCH net 4/5] net: dsa: mt7530: disable regulators on setup failure Haoran Wang
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ 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 related [flat|nested] 7+ 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 3/5] net: dsa: mt7530: register the GPIO controller last in setup Haoran Wang
@ 2026-11-24 8:33 ` netdev-bot+sinfo
5 siblings, 0 replies; 7+ 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] 7+ messages in thread
end of thread, other threads:[~2026-11-24 8:33 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 1/5] net: dsa: mt7530: disable regulators on switch teardown 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 5/5] net: dsa: mt7530: disable regulators on mt753x_setup() failure Haoran Wang
2026-11-24 8:25 ` [PATCH net 4/5] net: dsa: mt7530: disable regulators on setup failure Haoran Wang
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:33 ` [PATCH net 0/5] net: dsa: mt7530: fix regulator disable on teardown and error paths netdev-bot+sinfo
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox