Thread View: linux.kernel.netdev
3 messages
3 total messages
Started by Xiangwu Lai
Mon, 23 Nov 2026 02:24
[PATCH v3] net: dsa: mt7530: manage the core and io regulators with devm actions
Author: Xiangwu Lai
Date: Mon, 23 Nov 2026 02:24
Date: Mon, 23 Nov 2026 02:24
155 lines
14004 bytes
14004 bytes
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 pair each regulator_enable() with a
devm_add_action_or_reset() that disables it again. This covers every
error path after the enables, and replaces the explicit disables in
mt7530_remove(), so the enables and disables stay balanced in all
combinations of probe, setup and unbind.
Found by code inspection, the issue has not been triggered at runtime
and no MT7530 hardware was available for testing. The visible symptom
of the leak would be both regulators staying powered after a failed
probe and a WARN_ON(enable_count) splat from the regulator core when
the devm-acquired handles are released with a nonzero enable count.
Fixes: b8f126a8d543 ("net-next: dsa: add dsa support for Mediatek MT7530 switch")
Signed-off-by: Xiangwu Lai <laixiangwu@cmss.chinamobile.com>
---
Changes in v3:
- Replaced the setup error-path unwinding of v2 with devm-managed regulator
enables in mt7530_probe(), and removed the explicit disables from
mt7530_remove(). The late error paths outside mt7530_setup() (IRQ chip
and MDIO bus registration, SGMII PCS creation, the DSA core) are now
covered too, as suggested in the review of v1 by the netdev AI bot.
Link: https://lore.kernel.org/r/20261119060424.1476-1-laixiangwu@cmss.chinamobile.com
drivers/net/dsa/mt7530-mdio.c | 48 +++++++++++++++++++++++++----------
drivers/net/dsa/mt7530.c | 18 -------------
2 files changed, 35 insertions(+), 31 deletions(-)
diff --git a/drivers/net/dsa/mt7530-mdio.c b/drivers/net/dsa/mt7530-mdio.c
index 0be107dc6..99432d658 100644
--- a/drivers/net/dsa/mt7530-mdio.c
+++ b/drivers/net/dsa/mt7530-mdio.c
@@ -155,6 +155,14 @@ static const struct regmap_config regmap_config = {
.unlock = mt7530_mdio_regmap_unlock,
};
+static void
+mt7530_disable_regulator(void *data)
+{
+ struct regulator *regulator = data;
+
+ regulator_disable(regulator);
+}
+
static int
mt7530_probe(struct mdio_device *mdiodev)
{
@@ -210,6 +218,32 @@ 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;
+ }
+ ret = devm_add_action_or_reset(&mdiodev->dev,
+ mt7530_disable_regulator,
+ priv->core_pwr);
+ if (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);
+ return ret;
+ }
+ ret = devm_add_action_or_reset(&mdiodev->dev,
+ mt7530_disable_regulator,
+ priv->io_pwr);
+ if (ret)
+ return ret;
}
rc.lock_arg = &priv->bus->mdio_lock;
@@ -228,23 +262,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 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
Re: [PATCH v3] net: dsa: mt7530: manage the core and io regulators with devm actions
Author: Andrew Lunn
Date: Mon, 23 Nov 2026 14:46
Date: Mon, 23 Nov 2026 14:46
27 lines
9109 bytes
9109 bytes
> Move the enables to mt7530_probe(), right after the regulators are
> acquired
Please add an explanation why this is safe. Since the original code
did not do this, there might be a reason it is done later.
> , and pair each regulator_enable() with a
> devm_add_action_or_reset() that disables it again.
https://www.kernel.org/doc/html/latest/process/maintainer-netdev.html
Using device-managed and cleanup.h constructs
Netdev remains skeptical about promises of all “auto-cleanup” APIs,
including even devm_ helpers, historically. They are not the preferred
style of implementation, merely an acceptable one.
This is maybe one case where devm is the wrong solution. Please keep
with the normal way of doing cleanup.
> Fixes: b8f126a8d543 ("net-next: dsa: add dsa support for Mediatek MT7530 switch")
Who does this bother?
Andrew
Re: [PATCH v3] net: dsa: mt7530: manage the core and io regulators with devm actions
Author: Xiangwu Lai
Date: Tue, 24 Nov 2026 01:38
Date: Tue, 24 Nov 2026 01:38
55 lines
11148 bytes
11148 bytes
Hi Andrew,
Thanks for the review of "[PATCH v3] net: dsa: mt7530: manage the core
and io regulators with devm actions"
(https://lore.kernel.org/r/20261123022415.433-1-laixiangwu@cmss.chinamobile.com).
> > Move the enables to mt7530_probe(), right after the regulators are
> > acquired
>
> Please add an explanation why this is safe. Since the original code
> did not do this, there might be a reason it is done later.
Done in v4. The short version: 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 has no such supplies (skipped by the ID_MT7530 guards) and the
MT7988 MMIO variant has no regulators at all. I could not find a
reason in the history of b8f126a8d543 why the enables were done in
setup rather than probe - it just grew there when the driver was
originally written.
> This is maybe one case where devm is the wrong solution. Please keep
> with the normal way of doing cleanup.
Understood - v4 drops the devm_add_action_or_reset() calls. The
enables stay in mt7530_probe(), but a later failure now unwinds with
plain error labels, and the explicit disables in mt7530_remove() are
restored. This keeps every failure path balanced: a failed probe
always unwinds (including -EPROBE_DEFER retries), and a switch that
stays bound is disabled exactly once by mt7530_remove().
> > Fixes: b8f126a8d543 ("net-next: dsa: add dsa support for Mediatek MT7530 switch")
>
> Who does this bother?
Honestly: nobody has reported it. I found the leak by code inspection
and have no MT7530 hardware. In-tree, the boards that wire these
supplies are the MT7623 ones (mt7623n-bananapi-bpi-r2 and
mt7623n-rfb-emmc via mt7623a.dtsi), and they connect them to switchable
MT6323 PMIC outputs, so there the leak would keep the supplies on
after a failed probe and trip the WARN_ON(enable_count) in
_regulator_put() when the devm handles are released. It is a
robustness fix rather than a fix for an observed failure. If you
prefer, I am happy to drop the Fixes tag so it does not go to
stable - your call.
v4 is here:
[PATCH v4] net: dsa: mt7530: enable the regulators in probe() and unwind on error
https://lore.kernel.org/r/20261124013422.1408-1-laixiangwu@cmss.chinamobile.com
Best regards,
Xiangwu Lai
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads