From: netdev-bot+sashiko@kernel.org
To: laixiangwu@cmss.chinamobile.com
Cc: chester.a.unal@arinc9.com, daniel@makrotopia.org, andrew@lunn.ch,
olteanv@gmail.com, sean.wang@mediatek.com,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
kuba@kernel.org
Subject: Re: [PATCH] net: dsa: mt7530: fix regulator leak in mt7530_setup()
Date: Sun, 22 Nov 2026 02:06:20 +0000 [thread overview]
Message-ID: <179531318026.3135.909782780821579093@kernel.org> (raw)
In-Reply-To: <20261118014114.1855-1-laixiangwu@cmss.chinamobile.com>
Thank you for your contribution! Sashiko AI review found 3 potential
issue(s) to consider.
Critical: 0 · High: 1 · 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).
- [High] The fix is incomplete.
- [Medium] The new err_powers/err_disable_core_pwr paths in
mt7530_setup() disable core_pwr/io_pwr, but mt7530_remove() was not…
- [Low] This is speculative and depends on the hardware.
--
net: dsa: mt7530: fix regulator leak in mt7530_setup()
This commit adds two error labels to mt7530_setup(). Error paths taken
after the core and io regulators are enabled now disable them again. The
common cleanup is guarded by a priv->id == ID_MT7530 check because MT7621
shares the sw_setup callback but never enables the regulators.
> diff --git a/drivers/net/dsa/mt7530.c b/drivers/net/dsa/mt7530.c
> index d5a199293f78a..46f827838a519 100644
> --- a/drivers/net/dsa/mt7530.c
> +++ b/drivers/net/dsa/mt7530.c
[ ... ]
> @@ -2579,16 +2581,27 @@ 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_powers;
> }
> #endif /* CONFIG_GPIOLIB */
>
> /* Flush the FDB table */
> ret = mt7530_fdb_cmd(priv, MT7530_FDB_FLUSH, NULL);
> if (ret < 0)
> - return ret;
> + goto err_powers;
>
> return 0;
[Severity: High]
Is this fix complete? mt7530_setup() is only the sw_setup callback. On
success it returns 0 with both core_pwr and io_pwr enabled.
The real ds->ops->setup is mt753x_setup(), and it can still fail after
that without disabling either supply:
drivers/net/dsa/mt7530.c:mt753x_setup() {
int ret = priv->info->sw_setup(ds);
...
ret = mt7530_setup_irq(priv);
if (ret)
return ret;
ret = mt7530_setup_mdio(priv);
if (ret)
return ret;
...
}
mt7530_setup_irq() can return -EPROBE_DEFER from of_irq_get(), or fail in
devm_regmap_add_irq_chip_fwnode(). mt7530_setup_mdio() can fail in
devm_mdiobus_alloc() or devm_of_mdiobus_register(), and the latter can
also defer.
Later failures in the DSA core are not covered either. These include
dsa_switch_setup_tag_protocol(), user MII bus registration, and
dsa_tree_setup_ports/conduit/lags in dsa_tree_setup(). Those paths call
ds->ops->teardown, but mt753x_teardown() only cancels stats_work.
In all of these cases dsa_register_switch() fails and mt7530_probe()
returns the error. That means mt7530_remove() never runs, and it holds
the only matching regulator_disable() calls.
The devm regulator handles are then released with a non-zero
enable_count, which hits this warning:
drivers/regulator/core.c:_regulator_put() {
/* Docs say you must disable before calling regulator_put() */
WARN_ON(regulator->enable_count);
...
}
The provider's use_count is also never dropped. Each -EPROBE_DEFER retry
enables the supplies again with a new handle, so the count keeps growing
and the switch stays powered and out of reset with no driver bound.
Would it work better to move ownership of the regulators? For example,
probe could enable them and register a devm action to disable them.
Another option is to unwind in mt753x_setup() and mt753x_teardown() and
change mt7530_remove() to match.
> +
> +err_disable_core_pwr:
> + regulator_disable(priv->core_pwr);
> + return ret;
> +
> +err_powers:
> + if (priv->id == ID_MT7530) {
> + regulator_disable(priv->io_pwr);
> + regulator_disable(priv->core_pwr);
> + }
[Severity: Medium]
Can this leave mt7530_remove() disabling the regulators a second time?
mt7530_remove() was not changed, and it still disables both supplies
unconditionally:
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);
...
}
...
}
Consider a multi-switch DSA tree where the MT7530 probes first.
dsa_tree_setup() returns 0 while the tree is incomplete:
net/dsa/dsa.c:dsa_tree_setup() {
...
complete = dsa_tree_setup_routing_table(dst);
if (!complete)
return 0;
...
}
So the MT7530 driver binds before ops->setup has run. When the last
switch of the tree probes, mt753x_setup()->mt7530_setup() runs for the
MT7530 that is already bound.
If mt7530_setup() then fails, err_powers drops the consumer enable_count
to zero. The error goes back to the other switch's probe, and the MT7530
stays bound.
On a later unbind, mt7530_remove() calls regulator_disable() again. That
triggers the "unbalanced disables for %s" WARN in _regulator_disable(),
which returns -EIO. The driver also logs "Failed to disable core power"
and "Failed to disable io pwr".
Before this patch, a failed setup left the regulators enabled, so the
remove path was balanced.
[Severity: Low]
This one is speculative and depends on the hardware, but should the chip
be put back into reset before the supplies are cut here? Every goto
err_powers happens after mt7530_setup() has already released reset:
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);
}
err_powers only disables io_pwr and core_pwr. Suppose the reset GPIO is
present and the supplies really turn off. The SoC would then keep driving
the reset input at its run level into an unpowered chip, which could
back-power it through the input protection diodes.
mt7530_remove() already disables the regulators in the same order. This
error path is new code, though, and could assert reset first.
> + return ret;
> }
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261118014114.1855-1-laixiangwu%40cmss.chinamobile.com
prev parent reply other threads:[~2026-11-22 2:06 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-18 1:41 [PATCH] net: dsa: mt7530: fix regulator leak in mt7530_setup() Xiangwu Lai
2026-11-18 1:42 ` netdev-bot+sinfo
2026-11-19 6:07 ` Xiangwu Lai
2026-11-18 23:36 ` Andrew Lunn
2026-11-19 6:05 ` Xiangwu Lai
2026-11-22 2:06 ` netdev-bot+sashiko [this message]
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=179531318026.3135.909782780821579093@kernel.org \
--to=netdev-bot+sashiko@kernel.org \
--cc=andrew@lunn.ch \
--cc=chester.a.unal@arinc9.com \
--cc=daniel@makrotopia.org \
--cc=kuba@kernel.org \
--cc=laixiangwu@cmss.chinamobile.com \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=olteanv@gmail.com \
--cc=sean.wang@mediatek.com \
/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