[PATCH v2] net: dsa: mt7530: disable the power rails on setup failure
From: Haoran Wang
Date: Mon Nov 23 2026 - 06:10:01 EST
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@xxxxxxxxxxxxxxxxxx>
---
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,