[PATCH net 4/5] net: dsa: mt7530: disable regulators on setup failure

From
Haoran Wang <hidden>
Date
2026-11-24 08:27:31
Also in
linux-mediatek, lkml, netdev
Reply to
Haoran Wang, 2026-11-24
Once the core and io regulators have been enabled, every later failure
in mt7530_setup() returned without disabling them, leaving the rails
enabled and making the regulator core warn when devres later puts an
enabled regulator.

Route those failure paths to a common error label that disables both
regulators, and disable the already enabled core regulator if enabling
the io regulator fails.

Fixes: b8f126a8d543 ("net-next: dsa: add dsa support for Mediatek MT7530 switch")
Signed-off-by: Haoran Wang <redacted>
---
 drivers/net/dsa/mt7530.c | 22 +++++++++++++++-------
 1 file changed, 15 insertions(+), 7 deletions(-)
diff --git a/drivers/net/dsa/mt7530.c b/drivers/net/dsa/mt7530.c
index e208d942b577..1ac4ac1a0566 100644
--- a/drivers/net/dsa/mt7530.c
+++ b/drivers/net/dsa/mt7530.c
@@ -2435,6 +2435,7 @@ mt7530_setup(struct dsa_switch *ds)
 		if (ret < 0) {
 			dev_err(priv->dev, "Failed to enable io pwr: %d\n",
 				ret);
+			regulator_disable(priv->core_pwr);
 			return ret;
 		}
 	}
@@ -2457,20 +2458,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 */
@@ -2537,7 +2540,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)) {
@@ -2564,7 +2567,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)
@@ -2588,17 +2591,22 @@ mt7530_setup(struct dsa_switch *ds)
 	/* Flush the FDB table */
 	ret = mt7530_fdb_cmd(priv, MT7530_FDB_FLUSH, NULL);
 	if (ret < 0)
-		return ret;
+		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 */
 
 	return 0;
+
+err_disable_pwrs:
+	mt7530_disable_pwrs(priv);
+
+	return ret;
 }
 
 static int

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