[PATCH net-next v2 5/5] net: dsa: mt7530: disable regulators on mt753x_setup() failure

From: Haoran Wang

Date: Thu Dec 03 2026 - 01:49:15 EST


mt753x_setup() calls the per-variant sw_setup() (mt7530_setup() for the
MT7530), which enables the regulators, but the steps that follow returned
on error without disabling them. The common case is mt7530_setup_irq()
returning -EPROBE_DEFER, which leaves the rails on and re-enables them on
every re-probe.

Route all failure paths after sw_setup() to a shared error label that
frees the mdio irq and disables the regulators, and add a sw_teardown()
callback symmetric with sw_setup() so that disabling goes through the
same per-variant hook as enabling. For the MT7530 variants the callback
disables the core and io regulators.

Fixes: ba751e28d442 ("net: dsa: mt7530: add interrupt support")
Signed-off-by: Haoran Wang <wanghr2026@xxxxxxxxxxxxxxxxxx>
---
drivers/net/dsa/mt7530.c | 32 ++++++++++++++++++++++++++------
drivers/net/dsa/mt7530.h | 2 ++
2 files changed, 28 insertions(+), 6 deletions(-)

diff --git a/drivers/net/dsa/mt7530.c b/drivers/net/dsa/mt7530.c
index 1ae0ca278969..32cf4a1ce2ac 100644
--- a/drivers/net/dsa/mt7530.c
+++ b/drivers/net/dsa/mt7530.c
@@ -2395,6 +2395,14 @@ mt7530_disable_pwrs(struct mt7530_priv *priv)
ret);
}

+static void
+mt7530_teardown(struct dsa_switch *ds)
+{
+ struct mt7530_priv *priv = ds->priv;
+
+ mt7530_disable_pwrs(priv);
+}
+
static int
mt7530_setup(struct dsa_switch *ds)
{
@@ -3232,11 +3240,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++) {
@@ -3248,15 +3256,24 @@ 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)
+ goto err_free_irq;

- if (!ret && priv->bus) {
+ if (priv->bus) {
mt7530_stats_refresh(priv);
schedule_delayed_work(&priv->stats_work,
MT7530_STATS_POLL_INTERVAL);
}

+ return 0;
+
+err_free_irq:
+ if (priv->irq_domain)
+ mt7530_free_mdio_irq(priv);
+err_disable_pwrs:
+ if (priv->info->sw_teardown)
+ priv->info->sw_teardown(ds);
+
return ret;
}

@@ -3268,7 +3285,8 @@ mt753x_teardown(struct dsa_switch *ds)
if (priv->bus)
cancel_delayed_work_sync(&priv->stats_work);

- mt7530_disable_pwrs(priv);
+ if (priv->info->sw_teardown)
+ priv->info->sw_teardown(ds);
}

static int mt753x_set_mac_eee(struct dsa_switch *ds, int port,
@@ -3484,6 +3502,7 @@ const struct mt753x_info mt753x_table[] = {
.id = ID_MT7621,
.pcs_ops = &mt7530_pcs_ops,
.sw_setup = mt7530_setup,
+ .sw_teardown = mt7530_teardown,
.phy_read_c22 = mt7530_phy_read_c22,
.phy_write_c22 = mt7530_phy_write_c22,
.phy_read_c45 = mt7530_phy_read_c45,
@@ -3495,6 +3514,7 @@ const struct mt753x_info mt753x_table[] = {
.id = ID_MT7530,
.pcs_ops = &mt7530_pcs_ops,
.sw_setup = mt7530_setup,
+ .sw_teardown = mt7530_teardown,
.phy_read_c22 = mt7530_phy_read_c22,
.phy_write_c22 = mt7530_phy_write_c22,
.phy_read_c45 = mt7530_phy_read_c45,
diff --git a/drivers/net/dsa/mt7530.h b/drivers/net/dsa/mt7530.h
index 2bbbe617b52e..c413a3836ff5 100644
--- a/drivers/net/dsa/mt7530.h
+++ b/drivers/net/dsa/mt7530.h
@@ -853,6 +853,7 @@ struct mt753x_pcs {
* @id: Holding the identifier to a switch model
* @pcs_ops: Holding the pointer to the MAC PCS operations structure
* @sw_setup: Holding the handler to a device initialization
+ * @sw_teardown: Holding the handler to a device deinitialization
* @phy_read_c22: Holding the way reading PHY port using C22
* @phy_write_c22: Holding the way writing PHY port using C22
* @phy_read_c45: Holding the way reading PHY port using C45
@@ -867,6 +868,7 @@ struct mt753x_info {
const struct phylink_pcs_ops *pcs_ops;

int (*sw_setup)(struct dsa_switch *ds);
+ void (*sw_teardown)(struct dsa_switch *ds);
int (*phy_read_c22)(struct mt7530_priv *priv, int port, int regnum);
int (*phy_write_c22)(struct mt7530_priv *priv, int port, int regnum,
u16 val);