* [PATCH v2] net: dsa: mt7530: disable the power rails on setup failure
@ 2026-11-23 11:09 Haoran Wang
2026-11-23 11:12 ` netdev-bot+sinfo
0 siblings, 1 reply; 3+ messages in thread
From: Haoran Wang @ 2026-11-23 11:09 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 only
mt7530_remove() disables them. A failed probe never reaches .remove(),
so the rails stay enabled on every setup failure path, and the regulator
core warns when devres later puts an enabled regulator. The common case
is mt7530_setup_irq() returning -EPROBE_DEFER, where each re-probe
enables the rails again.
Tie the regulator lifetime to the switch setup/teardown pair. Disable the
rails in mt753x_teardown() and on the mt753x_setup() error paths after
sw_setup() succeeds, and drop the now-redundant disables from
mt7530_remove(). This also avoids an unbalanced disable when a switch in
a multi-switch tree fails setup while already bound. Move
mt7530_setup_gpio() after the FDB flush so the gpiochip is not left
registered when the rails are dropped.
Signed-off-by: Haoran Wang <wanghr2026@mail.zgclab.edu.cn>
---
Changes in v2:
- Address the High severity finding (incomplete fix). Tie the regulator
lifetime to the setup/teardown pair instead of using local labels in
mt7530_setup(). The rails are now disabled in mt753x_teardown() and on
the mt753x_setup() error paths after sw_setup() succeeds, and the
redundant disables are dropped from mt7530_remove(). This covers the
-EPROBE_DEFER case in mt7530_setup_irq() and the post-setup
dsa_switch_setup() and dsa_tree_setup() failures.
- Address the Medium severity finding (unbalanced disable in
mt7530_remove()). Disabling in teardown, which only runs once the tree
is actually set up, avoids the second disable for a switch that fails
setup while it is already bound in a multi-switch tree.
- Address the Low severity finding (gpiochip left registered when the
rails are dropped). Move mt7530_setup_gpio() after the FDB flush so no
failure path leaves the gpiochip registered after the rails are disabled.
- Leave the other Low severity finding (assert reset before dropping the
rails) out of this fix. It is speculative and matches the existing
mt7530_remove() ordering.
drivers/net/dsa/mt7530-mdio.c | 14 +--------
drivers/net/dsa/mt7530.c | 67 ++++++++++++++++++++++++++++++++-----------
2 files changed, 51 insertions(+), 30 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..5bbeed0491c4 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)
{
@@ -2425,7 +2435,7 @@ mt7530_setup(struct dsa_switch *ds)
if (ret < 0) {
dev_err(priv->dev, "Failed to enable io pwr: %d\n",
ret);
- return ret;
+ goto err_disable_core_pwr;
}
}
@@ -2447,20 +2457,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 */
@@ -2527,7 +2539,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)) {
@@ -2554,7 +2566,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)
@@ -2575,20 +2587,31 @@ mt7530_setup(struct dsa_switch *ds)
}
}
+ /* Flush the FDB table */
+ ret = mt7530_fdb_cmd(priv, MT7530_FDB_FLUSH, NULL);
+ if (ret < 0)
+ 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 */
- /* Flush the FDB table */
- ret = mt7530_fdb_cmd(priv, MT7530_FDB_FLUSH, NULL);
- if (ret < 0)
- return ret;
-
return 0;
+
+err_disable_pwrs:
+ mt7530_disable_pwrs(priv);
+
+ return ret;
+
+err_disable_core_pwr:
+ if (priv->id == ID_MT7530)
+ regulator_disable(priv->core_pwr);
+
+ return ret;
}
static int
@@ -3205,11 +3228,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++) {
@@ -3221,15 +3244,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) {
+ if (priv->irq_domain)
+ mt7530_free_mdio_irq(priv);
+ goto err_disable_pwrs;
+ }
- if (!ret && priv->bus) {
+ if (priv->bus) {
mt7530_stats_refresh(priv);
schedule_delayed_work(&priv->stats_work,
MT7530_STATS_POLL_INTERVAL);
}
+ return 0;
+
+err_disable_pwrs:
+ mt7530_disable_pwrs(priv);
+
return ret;
}
@@ -3240,6 +3271,8 @@ mt753x_teardown(struct dsa_switch *ds)
if (priv->bus)
cancel_delayed_work_sync(&priv->stats_work);
+
+ mt7530_disable_pwrs(priv);
}
static int mt753x_set_mac_eee(struct dsa_switch *ds, int port,
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2] net: dsa: mt7530: disable the power rails on setup failure
2026-11-23 11:09 [PATCH v2] net: dsa: mt7530: disable the power rails on setup failure Haoran Wang
@ 2026-11-23 11:12 ` netdev-bot+sinfo
2026-11-23 11:24 ` 王浩然
0 siblings, 1 reply; 3+ messages in thread
From: netdev-bot+sinfo @ 2026-11-23 11:12 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] 3+ messages in thread
* Re: Re: [PATCH v2] net: dsa: mt7530: disable the power rails on setup failure
2026-11-23 11:12 ` netdev-bot+sinfo
@ 2026-11-23 11:24 ` 王浩然
0 siblings, 0 replies; 3+ messages in thread
From: 王浩然 @ 2026-11-23 11:24 UTC (permalink / raw)
To: netdev-bot+sinfo
Cc: chester.a.unal, daniel, andrew, olteanv, davem, edumazet, kuba,
pabeni, matthias.bgg, angelogioacchino.delregno, netdev,
linux-arm-kernel, linux-mediatek, linux-kernel
- How it was discovered. Static scanning, not a runtime report. I
scanned for regulator_enable() calls and checked that each one has a
matching regulator_disable() on the error paths. mt7530_setup()
enables the core and io rails, but only mt7530_remove() disables them,
so a probe that fails after the enable has no matching disable.
- Whether it was triggered. It was not triggered, and I did not
reproduce it on hardware.
Thanks,
Haoran
> -----原始邮件-----
> 发件人: netdev-bot+sinfo@kernel.org
> 发送时间:2026-11-23 19:12:38 (星期一)
> 收件人: "Haoran Wang" <wanghr2026@mail.zgclab.edu.cn>
> 抄送: 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
> 主题: Re: [PATCH v2] net: dsa: mt7530: disable the power rails on setup failure
>
> 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] 3+ messages in thread
end of thread, other threads:[~2026-11-23 11:25 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-23 11:09 [PATCH v2] net: dsa: mt7530: disable the power rails on setup failure Haoran Wang
2026-11-23 11:12 ` netdev-bot+sinfo
2026-11-23 11:24 ` 王浩然
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox