[PATCH net-next v2 1/5] net: dsa: mt7530: disable regulators on switch teardown

Haoran Wang wanghr2026 at mail.zgclab.edu.cn
Wed Dec 2 22:48:23 PST 2026


mt7530_setup() enables the core and io regulators, so they should be
disabled by the matching teardown callback, not by the driver remove
callback. teardown is the counterpart of setup and runs for every switch
that was successfully set up, whereas remove() only runs when the whole
driver is unbound.

Move the regulator disable from mt7530_remove() to mt753x_teardown(),
after the stats polling work is cancelled so that no poll can run against
an unpowered switch. The regulator_disable() error reporting is kept.

A switch in a multi-switch tree whose sibling fails to set up is torn
down without its driver reaching remove(), so its regulators were left
enabled until now.

Fixes: b8f126a8d543 ("net-next: dsa: add dsa support for Mediatek MT7530 switch")
Signed-off-by: Haoran Wang <wanghr2026 at mail.zgclab.edu.cn>
Reviewed-by: Andrew Lunn <andrew at lunn.ch>
---
 drivers/net/dsa/mt7530-mdio.c | 14 +-------------
 drivers/net/dsa/mt7530.c      | 13 +++++++++++++
 2 files changed, 14 insertions(+), 13 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..c2f12ae2c6d7 100644
--- a/drivers/net/dsa/mt7530.c
+++ b/drivers/net/dsa/mt7530.c
@@ -3237,9 +3237,22 @@ static void
 mt753x_teardown(struct dsa_switch *ds)
 {
 	struct mt7530_priv *priv = ds->priv;
+	int ret;
 
 	if (priv->bus)
 		cancel_delayed_work_sync(&priv->stats_work);
+
+	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);
+	}
 }
 
 static int mt753x_set_mac_eee(struct dsa_switch *ds, int port,




More information about the linux-arm-kernel mailing list