* [PATCH] net: dsa: mt7530: disable the power rails on setup failure
@ 2026-11-19 8:15 Wang Haoran
2026-11-19 8:17 ` netdev-bot+sinfo
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Wang Haoran @ 2026-11-19 8:15 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, wanghr2026
mt7530_setup() enables the core and io regulators and then has several
failure returns (io rail enable failure, reset timeout, unsupported chip id
or 20 MHz XTAL, vlan0 setup, phy muxing, gpio setup, fdb flush) that all
return without disabling the already enabled rails. A failed probe never
reaches mt7530_remove(), which is the only place the regulators are
disabled, so after a setup failure the switch rails stay enabled until the
next attempt re-enables them and the enable counts keep growing.
Unwind the enables on the error paths, guarding each disable by
priv->id == ID_MT7530 since the rails are only enabled for that variant.
Signed-off-by: Wang Haoran <wanghr2026@mail.zgclab.edu.cn>
Fixes: b8f126a8d543 ("net-next: dsa: add dsa support for Mediatek MT7530 switch")
---
diff --git a/drivers/net/dsa/mt7530.c b/drivers/net/dsa/mt7530.c
index d5a199293f78..769f733f80d2 100644
--- a/drivers/net/dsa/mt7530.c
+++ b/drivers/net/dsa/mt7530.c
@@ -2425,7 +2425,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 +2447,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 +2529,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 +2556,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)
@@ -2579,16 +2581,25 @@ mt7530_setup(struct dsa_switch *ds)
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;
+ goto err_disable_pwrs;
return 0;
+
+err_disable_pwrs:
+ if (priv->id == ID_MT7530)
+ regulator_disable(priv->io_pwr);
+err_disable_core_pwr:
+ if (priv->id == ID_MT7530)
+ regulator_disable(priv->core_pwr);
+
+ return ret;
}
static int
---
The vulnerability was found by static analysis.
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH] net: dsa: mt7530: disable the power rails on setup failure
2026-11-19 8:15 [PATCH] net: dsa: mt7530: disable the power rails on setup failure Wang Haoran
@ 2026-11-19 8:17 ` netdev-bot+sinfo
2026-11-19 15:08 ` Andrew Lunn
2026-11-23 8:26 ` netdev-bot+sashiko
2 siblings, 0 replies; 4+ messages in thread
From: netdev-bot+sinfo @ 2026-11-19 8:17 UTC (permalink / raw)
To: Wang Haoran
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] 4+ messages in thread
* Re: [PATCH] net: dsa: mt7530: disable the power rails on setup failure
2026-11-19 8:15 [PATCH] net: dsa: mt7530: disable the power rails on setup failure Wang Haoran
2026-11-19 8:17 ` netdev-bot+sinfo
@ 2026-11-19 15:08 ` Andrew Lunn
2026-11-23 8:26 ` netdev-bot+sashiko
2 siblings, 0 replies; 4+ messages in thread
From: Andrew Lunn @ 2026-11-19 15:08 UTC (permalink / raw)
To: Wang Haoran
Cc: chester.a.unal, daniel, olteanv, davem, edumazet, kuba, pabeni,
matthias.bgg, angelogioacchino.delregno, netdev, linux-arm-kernel,
linux-mediatek, linux-kernel
> Fixes: b8f126a8d543 ("net-next: dsa: add dsa support for Mediatek MT7530 switch")
https://www.kernel.org/doc/html/latest/process/stable-kernel-rules.html
Does this bother anybody?
https://www.kernel.org/doc/html/latest/process/maintainer-netdev.html
Andrew
---
pw-bot: cr
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] net: dsa: mt7530: disable the power rails on setup failure
2026-11-19 8:15 [PATCH] net: dsa: mt7530: disable the power rails on setup failure Wang Haoran
2026-11-19 8:17 ` netdev-bot+sinfo
2026-11-19 15:08 ` Andrew Lunn
@ 2026-11-23 8:26 ` netdev-bot+sashiko
2 siblings, 0 replies; 4+ messages in thread
From: netdev-bot+sashiko @ 2026-11-23 8:26 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 4 potential
issue(s) to consider.
Critical: 0 · High: 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).
- [High] The fix is incomplete.
- [Medium] The new error-path disable in mt7530_setup() can be followed
by a second disable of the same rails, because mt7530_remove()…
- [Low] In mt7530_setup(), suppose mt7530_setup_gpio() has registered the
GPIO chip with devm_gpiochip_add_data() and the later…
- [Low] Speculative.
--
net: dsa: mt7530: disable the power rails on setup failure
This commit changes the early returns in mt7530_setup() that come after
the core and io regulator enables. They now jump to new unwind labels,
which disable io_pwr and core_pwr when priv->id == ID_MT7530. The goal is
to stop the switch rails from staying enabled after a failed probe.
> diff --git a/drivers/net/dsa/mt7530.c b/drivers/net/dsa/mt7530.c
> index d5a199293f78a..769f733f80d2a 100644
> --- a/drivers/net/dsa/mt7530.c
> +++ b/drivers/net/dsa/mt7530.c
[ ... ]
> @@ -2579,16 +2581,25 @@ mt7530_setup(struct dsa_switch *ds)
> 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;
> + goto err_disable_pwrs;
[Severity: Low]
Suppose mt7530_setup_gpio() has already registered the gpiochip with
devm_gpiochip_add_data() and the FDB flush then fails. This goto turns
off io_pwr and core_pwr while the gpiochip is still registered.
The gpiochip is only removed when devres on priv->dev is released. In a
single-switch tree that happens at the end of the failed probe. If another
switch's probe drove the tree setup and the MT7530 stays bound, it does
not happen at all.
During that window, could mt7530_gpio_get(), mt7530_gpio_set() and
mt7530_gpio_direction_*() do regmap accesses over MDIO to a switch whose
supplies are off? Should the gpiochip be removed before the hardware
loses power?
>
> return 0;
> +
> +err_disable_pwrs:
> + if (priv->id == ID_MT7530)
> + regulator_disable(priv->io_pwr);
> +err_disable_core_pwr:
> + if (priv->id == ID_MT7530)
> + regulator_disable(priv->core_pwr);
> +
> + return ret;
> }
[Severity: High]
Does this fully cover the leak described in the commit message? These
labels only handle failures inside mt7530_setup(). The rails can still be
left enabled when something fails after mt7530_setup() has returned 0.
mt753x_setup() calls priv->info->sw_setup(), which is mt7530_setup() for
ID_MT7530, and then does this:
drivers/net/dsa/mt7530.c:mt753x_setup() {
...
ret = mt7530_setup_irq(priv);
if (ret)
return ret;
ret = mt7530_setup_mdio(priv);
if (ret)
return ret;
...
}
mt7530_setup_irq() can fail with -EPROBE_DEFER from of_irq_get() when the
interrupt parent hasn't probed yet. Neither of these returns disables
core_pwr or io_pwr.
Something similar happens in dsa_switch_setup() and dsa_tree_setup().
Failures after ds->ops->setup() succeeds (tag protocol setup, user MDIO
bus, ports, conduit, lags) only unwind through ds->ops->teardown, which is
mt753x_teardown():
static void
mt753x_teardown(struct dsa_switch *ds)
{
struct mt7530_priv *priv = ds->priv;
if (priv->bus)
cancel_delayed_work_sync(&priv->stats_work);
}
In all of these cases dsa_register_switch() fails, so mt7530_probe() fails
and mt7530_remove() never runs. When devres later calls regulator_put(),
the regulator core would hit WARN_ON(regulator->enable_count). On
-EPROBE_DEFER, every re-probe enables the rails again:
mt7530_probe()
dsa_register_switch()
dsa_tree_setup()
dsa_switch_setup()
mt753x_setup()
mt7530_setup() <- rails enabled, returns 0
mt7530_setup_irq() <- -EPROBE_DEFER, rails left enabled
Would it be better to tie the regulator lifetime to the whole
setup/teardown pair instead of using local labels in mt7530_setup()? One
option is to disable the rails in mt753x_teardown() and on the
mt753x_setup() error paths, and change mt7530_remove() to match. Another
is to use devm-managed enables.
[Severity: Medium]
Can these new disables lead to unbalanced regulator disables later in
mt7530_remove()?
mt7530_remove() in drivers/net/dsa/mt7530-mdio.c disables both rails
whenever priv->id == ID_MT7530. It does not know whether setup succeeded:
drivers/net/dsa/mt7530-mdio.c:mt7530_remove() {
...
if (priv->id == ID_MT7530) {
ret = regulator_disable(priv->core_pwr);
...
ret = regulator_disable(priv->io_pwr);
...
}
The driver supports port 5 as a DSA link (see the
dsa_is_dsa_port(priv->ds, 5) check in mt7530_setup_port5()). In a
multi-switch tree, dsa_tree_setup() returns 0 while the tree is
incomplete:
complete = dsa_tree_setup_routing_table(dst);
if (!complete)
return 0;
So mt7530_probe() can succeed, and mt7530_setup() then runs later from
another switch's dsa_register_switch(). Suppose it fails there after the
rails are enabled. These labels bring the enable counts back to 0, and the
error goes to the other switch's probe. The MT7530 stays bound with its
drvdata set.
On a later unbind, mt7530_remove() would call regulator_disable() again.
_regulator_disable() would then WARN with "unbalanced disables" and return
-EIO. Before this patch the rails stayed enabled after a setup failure, so
remove was balanced in this case.
[Severity: Low]
This one is speculative: should the switch be put back into reset before
the rails are dropped here? By the time any of these gotos run, the chip
has already been taken out of reset earlier in mt7530_setup():
if (priv->mcm) {
reset_control_assert(priv->rstc);
usleep_range(5000, 5100);
reset_control_deassert(priv->rstc);
} else {
gpiod_set_value_cansleep(priv->reset, 0);
usleep_range(5000, 5100);
gpiod_set_value_cansleep(priv->reset, 1);
}
On the non-MCM path, the host keeps driving the reset GPIO at its run
level, and the MDIO controller keeps driving MDC/MDIO, into a chip whose
supplies have just been released. On boards where regulator_disable()
actually removes the rail, could that back-power the I/O domain?
Asserting reset with gpiod_set_value_cansleep(priv->reset, 0) or
reset_control_assert(priv->rstc) before the regulator_disable() calls
would avoid this. mt7530_remove() has the same ordering, but this patch
adds a new power-off sequence that is reached more often.
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/1795076103951-10-8fa23d94%40mail.zgclab.edu.cn
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-11-23 8:47 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-19 8:15 [PATCH] net: dsa: mt7530: disable the power rails on setup failure Wang Haoran
2026-11-19 8:17 ` netdev-bot+sinfo
2026-11-19 15:08 ` Andrew Lunn
2026-11-23 8:26 ` netdev-bot+sashiko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox