* [PATCH v4] net: dsa: mt7530: enable the regulators in probe() and unwind on error
@ 2026-11-24 1:34 Xiangwu Lai
2026-11-25 1:34 ` netdev-bot+sashiko
0 siblings, 1 reply; 4+ messages in thread
From: Xiangwu Lai @ 2026-11-24 1:34 UTC (permalink / raw)
To: chester.a.unal
Cc: daniel, andrew, olteanv, sean.wang, netdev, linux-kernel,
netdev-bot+sashiko, Xiangwu Lai
mt7530_setup() enables the core and io regulators of the MT7530, but the
only matching regulator_disable() calls live in mt7530_remove(), which
never runs when the probe fails. A failure anywhere between the enables
and a fully registered switch - the remaining steps of mt7530_setup(),
the IRQ chip or MDIO bus registration in mt753x_setup() (both can also
return -EPROBE_DEFER), the SGMII PCS creation, or the DSA core itself -
therefore leaves both regulators enabled. The devm-acquired handles
are then released with a non-zero enable_count, which triggers the
WARN_ON() in _regulator_put(), and each probe deferral grows the count
further.
Move the enables to mt7530_probe(), right after the regulators are
acquired, and unwind them with plain error labels if a later step in
the probe fails. mt7530_setup() and mt7530_remove() keep their original
shape, so the enables and disables stay balanced in every combination of
probe, setup and unbind: a failed probe always unwinds, and a switch
that stays bound is always disabled exactly once by mt7530_remove().
Enabling the supplies this early is safe. Nothing accesses the switch
between the enables and dsa_register_switch(): the reset line has been
asserted since it was acquired in mt7530_probe() with GPIOD_OUT_LOW, so
the rails come up while the chip is held in reset, and mt7530_setup()
still releases the reset afterwards, unchanged. MT7621 does not have
these supplies and is skipped by the priv->id == ID_MT7530 guards, and
the MT7988 MMIO variant has no regulators at all.
Found by code inspection; the issue has not been triggered at runtime
and no MT7530 hardware was available for testing. The in-tree boards
that wire these supplies (the MT7623 boards mt7623n-bananapi-bpi-r2
and mt7623n-rfb-emmc via mt7623a.dtsi) connect them to switchable
MT6323 PMIC outputs, so on those boards a failed probe would leave the
supplies on and trip the WARN_ON(enable_count) splat when the devm
handles are released.
Fixes: b8f126a8d543 ("net-next: dsa: add dsa support for Mediatek MT7530 switch")
Suggested-by: Andrew Lunn <andrew@lunn.ch>
Signed-off-by: Xiangwu Lai <laixiangwu@cmss.chinamobile.com>
---
Changes in v4:
- Drop the devm_add_action_or_reset() approach and unwind the regulators
with plain error labels in mt7530_probe(), and restore the explicit
disables in mt7530_remove(), as requested by Andrew Lunn.
- Extend the commit message: explain why enabling the regulators
early in probe() is safe, and state which boards are affected.
Link: https://lore.kernel.org/r/20261123022415.433-1-laixiangwu@cmss.chinamobile.com
drivers/net/dsa/mt7530-mdio.c | 38 ++++++++++++++++++++++++++++++++---
drivers/net/dsa/mt7530.c | 18 -----------------
2 files changed, 35 insertions(+), 21 deletions(-)
diff --git a/drivers/net/dsa/mt7530-mdio.c b/drivers/net/dsa/mt7530-mdio.c
index 0be107dc6..b1daefc90 100644
--- a/drivers/net/dsa/mt7530-mdio.c
+++ b/drivers/net/dsa/mt7530-mdio.c
@@ -210,18 +210,50 @@ mt7530_probe(struct mdio_device *mdiodev)
priv->io_pwr = devm_regulator_get(&mdiodev->dev, "io");
if (IS_ERR(priv->io_pwr))
return PTR_ERR(priv->io_pwr);
+
+ regulator_set_voltage(priv->core_pwr, 1000000, 1000000);
+ ret = regulator_enable(priv->core_pwr);
+ if (ret < 0) {
+ dev_err(&mdiodev->dev,
+ "Failed to enable core power: %d\n", ret);
+ return ret;
+ }
+
+ regulator_set_voltage(priv->io_pwr, 3300000, 3300000);
+ ret = regulator_enable(priv->io_pwr);
+ if (ret < 0) {
+ dev_err(&mdiodev->dev,
+ "Failed to enable io pwr: %d\n", ret);
+ goto err_disable_core_pwr;
+ }
}
rc.lock_arg = &priv->bus->mdio_lock;
priv->regmap = devm_regmap_init(priv->dev, &mt7530_regmap_bus,
priv, &rc);
- if (IS_ERR(priv->regmap))
- return PTR_ERR(priv->regmap);
+ if (IS_ERR(priv->regmap)) {
+ ret = PTR_ERR(priv->regmap);
+ goto err_disable_powers;
+ }
if (priv->id == ID_MT7531)
priv->create_sgmii = mt7531_create_sgmii;
- return dsa_register_switch(priv->ds);
+ ret = dsa_register_switch(priv->ds);
+ if (ret)
+ goto err_disable_powers;
+
+ return 0;
+
+err_disable_powers:
+ 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 void
diff --git a/drivers/net/dsa/mt7530.c b/drivers/net/dsa/mt7530.c
index 7781a63b4..b669a94d4 100644
--- a/drivers/net/dsa/mt7530.c
+++ b/drivers/net/dsa/mt7530.c
@@ -2411,24 +2411,6 @@ mt7530_setup(struct dsa_switch *ds)
ds->ageing_time_min = 2 * 1000;
ds->ageing_time_max = (AGE_CNT_MAX + 1) * (AGE_UNIT_MAX + 1) * 1000;
- if (priv->id == ID_MT7530) {
- regulator_set_voltage(priv->core_pwr, 1000000, 1000000);
- ret = regulator_enable(priv->core_pwr);
- if (ret < 0) {
- dev_err(priv->dev,
- "Failed to enable core power: %d\n", ret);
- return ret;
- }
-
- regulator_set_voltage(priv->io_pwr, 3300000, 3300000);
- ret = regulator_enable(priv->io_pwr);
- if (ret < 0) {
- dev_err(priv->dev, "Failed to enable io pwr: %d\n",
- ret);
- return ret;
- }
- }
-
/* Reset whole chip through gpio pin or memory-mapped registers for
* different type of hardware
*/
--
2.50.1.windows.1
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH v4] net: dsa: mt7530: enable the regulators in probe() and unwind on error
2026-11-24 1:34 [PATCH v4] net: dsa: mt7530: enable the regulators in probe() and unwind on error Xiangwu Lai
@ 2026-11-25 1:34 ` netdev-bot+sashiko
2026-11-25 2:24 ` Xiangwu Lai
0 siblings, 1 reply; 4+ messages in thread
From: netdev-bot+sashiko @ 2026-11-25 1:34 UTC (permalink / raw)
To: laixiangwu
Cc: chester.a.unal, daniel, andrew, olteanv, sean.wang, netdev,
linux-kernel, netdev-bot+sashiko, kuba
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] The commit message's safety argument for enabling the supplies
early in mt7530_probe() does not hold on the in-tree boards that run…
- [Low] The new error labels in mt7530_probe()
(err_disable_powers/err_disable_core_pwr, lines 247-253) cut the core…
--
net: dsa: mt7530: enable the regulators in probe() and unwind on error
This moves the MT7530 core and io regulator enables from mt7530_setup()
into mt7530_probe(). It also adds error labels that disable the supplies
again if regmap init or dsa_register_switch() fails. The aim is to stop a
failed or deferred probe from leaving the regulators enabled.
Link: https://lore.kernel.org/r/20261123022415.433-1-laixiangwu@cmss.chinamobile.com
> diff --git a/drivers/net/dsa/mt7530-mdio.c b/drivers/net/dsa/mt7530-mdio.c
> index e85ef2aceee56..2de5e26edad61 100644
> --- a/drivers/net/dsa/mt7530-mdio.c
> +++ b/drivers/net/dsa/mt7530-mdio.c
> @@ -209,18 +209,50 @@ mt7530_probe(struct mdio_device *mdiodev)
> priv->io_pwr = devm_regulator_get(&mdiodev->dev, "io");
> if (IS_ERR(priv->io_pwr))
> return PTR_ERR(priv->io_pwr);
> +
> + regulator_set_voltage(priv->core_pwr, 1000000, 1000000);
> + ret = regulator_enable(priv->core_pwr);
> + if (ret < 0) {
> + dev_err(&mdiodev->dev,
> + "Failed to enable core power: %d\n", ret);
> + return ret;
> + }
> +
> + regulator_set_voltage(priv->io_pwr, 3300000, 3300000);
> + ret = regulator_enable(priv->io_pwr);
> + if (ret < 0) {
> + dev_err(&mdiodev->dev,
> + "Failed to enable io pwr: %d\n", ret);
> + goto err_disable_core_pwr;
> + }
> }
[Severity: Medium]
Does the safety argument in the commit message hold when the switch is a
multi-chip module? The commit message says:
the reset line has been asserted since it was acquired in
mt7530_probe() with GPIOD_OUT_LOW, so the rails come up while the
chip is held in reset
When mediatek,mcm is set there is no reset GPIO. mt7530_probe() only gets
a handle to the reset control, and getting the handle does not assert it:
if (priv->mcm) {
...
priv->rstc = devm_reset_control_get(&mdiodev->dev, "mcm");
The first assert happens in mt7530_setup(). That function only runs from
dsa_register_switch() during tree setup:
if (priv->mcm) {
reset_control_assert(priv->rstc);
usleep_range(5000, 5100);
reset_control_deassert(priv->rstc);
With this patch the switch is powered, out of reset and running on its
power-on defaults from probe until mt7530_setup() runs. Before the patch,
the reset pulse came right after the enables.
The window now covers all of dsa_register_switch() up to setup. It
repeats on every -EPROBE_DEFER retry. It can also last indefinitely when
dsa_register_switch() returns 0 for a multi-switch tree that is not yet
complete.
Non-MCM boards without reset-gpios are affected the same way, because
devm_gpiod_get_optional() returns NULL there.
The list of affected boards also looks wrong:
The in-tree boards that wire these supplies (the MT7623 boards
mt7623n-bananapi-bpi-r2 and mt7623n-rfb-emmc via mt7623a.dtsi)
mt7623n-bananapi-bpi-r2.dts and mt7623n-rfb-emmc.dts include mt7623n.dtsi,
not mt7623a.dtsi. They set reset-gpios and the supplies inline.
The boards that get mediatek,mcm plus core-supply and io-supply from
mt7623a.dtsi are mt7623a-rfb-emmc.dts and mt7623a-rfb-nand.dts. Those are
the boards where the chip is not held in reset while the rails come up.
Could the commit message be corrected? Is the longer powered but
unconfigured window on these boards intended?
>
> rc.lock_arg = &priv->bus->mdio_lock;
[ ... ]
> - return dsa_register_switch(priv->ds);
> + ret = dsa_register_switch(priv->ds);
> + if (ret)
> + goto err_disable_powers;
> +
> + return 0;
> +
> +err_disable_powers:
> + 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: Low]
Is this teardown order safe when dsa_register_switch() fails after
mt753x_setup() has already run? Some ways this can happen:
- mt7530_setup_mdio() returns -EPROBE_DEFER after the IRQ chip was
added
- create_sgmii fails
- a later step in the DSA core fails
In that case, devm resources created during setup are still registered
on mdiodev->dev:
mt7530_setup_irq()
devm_regmap_add_irq_chip_fwnode(...)
mt7530_setup_mdio()
devm_of_mdiobus_register(dev, bus, mnp)
mt753x_teardown() only cancels stats_work. The IRQ chip and the internal
MDIO bus are therefore released by devres_release_all() after
mt7530_probe() returns, which is after these labels have already cut the
supplies.
If the threaded regmap-irq handler runs in that window, it reads
MT7530_SYS_INT_STS from an unpowered chip.
mt7530_setup() has also already deasserted the reset with
gpiod_set_value_cansleep(priv->reset, 1). Nothing reasserts it before
power is removed here.
Would it help to register the disables with devm right after the
enables? The other option is to reassert reset and release the setup
resources before disabling the supplies.
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261124013422.1408-1-laixiangwu%40cmss.chinamobile.com
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH v4] net: dsa: mt7530: enable the regulators in probe() and unwind on error
2026-11-25 1:34 ` netdev-bot+sashiko
@ 2026-11-25 2:24 ` Xiangwu Lai
2026-11-25 2:29 ` Xiangwu Lai
0 siblings, 1 reply; 4+ messages in thread
From: Xiangwu Lai @ 2026-11-25 2:24 UTC (permalink / raw)
To: netdev-bot+sashiko
Cc: Xiangwu Lai, chester.a.unal, daniel, andrew, olteanv, sean.wang,
netdev, linux-kernel, kuba
Hello,
On the review of v4 (Subject: [PATCH v4] net: dsa: mt7530: enable the
regulators in probe() and unwind on error,
https://lore.kernel.org/all/20261124013422.1408-1-laixiangwu@cmss.chinamobile.com/):
> [Severity: Medium]
> Does the safety argument in the commit message hold when the switch is a
> multi-chip module? ... When mediatek,mcm is set there is no reset GPIO.
> mt7530_probe() only gets a handle to the reset control, and getting the
> handle does not assert it ... The first assert happens in mt7530_setup()
> ... The boards that get mediatek,mcm plus core-supply and io-supply from
> mt7623a.dtsi are mt7623a-rfb-emmc.dts and mt7623a-rfb-nand.dts.
Both parts of this finding are correct, thank you. I verified:
- On the mcm path mt7530_probe() only calls devm_reset_control_get();
the first reset_control_assert() is at the top of mt7530_setup(),
which only runs from dsa_register_switch(). So on the mcm boards
the chip runs on its power-on defaults between probe and setup.
- The board list in the v4 commit message was wrong.
mt7623n-bananapi-bpi-r2.dts and mt7623n-rfb-emmc.dts include
mt7623n.dtsi and wire the supplies and reset-gpios inline; those
boards are held in reset while the rails come up. The boards that
get mediatek,mcm and the supplies from mt7623a.dtsi are
mt7623a-rfb-emmc.dts and mt7623a-rfb-nand.dts.
V5 with the corrected commit message is out; the diff is unchanged:
[PATCH v5] net: dsa: mt7530: enable the regulators in probe() and unwind on error
https://lore.kernel.org/all/20261125022147.377-1-laixiangwu@cmss.chinamobile.com/
The v5 message now scopes the reset-held argument to the reset-gpios
boards and describes the mcm window as it is, including that it
repeats on -EPROBE_DEFER and is unbounded while a multi-switch tree
waits for its other members.
> [Severity: Low]
> Is this teardown order safe when dsa_register_switch() fails after
> mt753x_setup() has already run? ... the IRQ chip and the internal MDIO
> bus are therefore released by devres_release_all() after mt7530_probe()
> returns, which is after these labels have already cut the supplies.
> If the threaded regmap-irq handler runs in that window, it reads
> MT7530_SYS_INT_STS from an unpowered chip.
The mechanics are correct: mt7530_setup_irq() registers the IRQ chip
with devm_regmap_add_irq_chip_fwnode() and mt7530_setup_mdio() with
devm_of_mdiobus_register(), both on the mdiodev, and mt753x_teardown()
only cancels stats_work, so those resources do live until
devres_release_all() after the probe returns.
I would scope the practical impact as follows:
- None of the in-tree MT7530 boards that wire the regulators
(mt7623a-rfb-emmc, mt7623a-rfb-nand, mt7623n-bananapi-bpi-r2,
mt7623n-rfb-emmc) wire the switch interrupt, so
mt7530_setup_irq() takes the "no interrupt support" exit and there
is no regmap-irq handler to run in the window.
- The create_sgmii() example path is MT7531, which has no regulators;
the error labels are guarded by priv->id == ID_MT7530 and are no-ops
there.
- devm was deliberately ruled out for this driver per the netdev
maintainer guidance (the disables are plain error labels on
request of the tree owner), so the "register the disables with
devm" suggestion is not an option here.
- mt7530_remove() in the unmodified driver also cuts the supplies
before the devm resources are released, so the probe error path
now mirrors the existing remove order rather than introducing a
brand new shape.
That said, asserting the reset control and releasing the setup
resources before disabling the supplies in the probe error path would
be a cleaner unwind, and I am happy to add it if the maintainers want
it; that is Andrew's call to make.
pw-bot: cr
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-11-25 2:29 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-24 1:34 [PATCH v4] net: dsa: mt7530: enable the regulators in probe() and unwind on error Xiangwu Lai
2026-11-25 1:34 ` netdev-bot+sashiko
2026-11-25 2:24 ` Xiangwu Lai
2026-11-25 2:29 ` Xiangwu Lai
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox