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

From
Haoran Wang <hidden>
Date
2026-11-24 08:27:21
Also in
linux-arm-kernel, linux-mediatek, lkml
Reply to
Haoran Wang, 2026-11-24
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. This is a plain code movement, with the error
reporting kept for now and cleaned up in a later patch.

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 <redacted>
---
 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,
Thread (15 messages) 15 messages, 4 authors, last reply 1d ago
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help