mt7530_setup() enables the "core" and "io" regulators of the MT7530, but none of the error paths that follow (reset timeout, unsupported chip ID, 20MHz XTAL, VLAN setup, PHY muxing, GPIO setup, FDB flush) disables them again, leaving both regulators enabled after a failed setup. Add error labels that disable what was enabled by then, chained in fall-through style so that the unwind mirrors the enable order and there is a single return (suggested by Andrew Lunn). MT7621 maps to the same sw_setup callback but skips the regulator section entirely, so both labels are guarded with a priv->id check to avoid unbalanced disables. Found by code inspection, the issue has not been triggered at runtime and no MT7530 hardware was available for testing. The visible symptom of the leak would be both regulators staying powered after a failed probe and a WARN_ON(enable_count) splat from the regulator core when the devm-acquired handles are released with a nonzero enable count. Fixes: b8f126a8d543 ("net-next: dsa: add dsa support for Mediatek MT7530 switch") Suggested-by: Andrew Lunn Signed-off-by: Xiangwu Lai --- Changes in v2: - restructure the new error labels into chained fall-through cleanup with a single return, as suggested by Andrew Lunn - describe how the issue was found and its expected runtime symptom in the commit message, as requested by the netdev sinfo bot Link: https://lore.kernel.org/all/20261118014114.1855-1-laixiangwu@cmss.chinamobile.com/ drivers/net/dsa/mt7530.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/drivers/net/dsa/mt7530.c b/drivers/net/dsa/mt7530.c index 7781a63b4..1637ea22f 100644 --- a/drivers/net/dsa/mt7530.c +++ b/drivers/net/dsa/mt7530.c @@ -2425,7 +2425,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 +2447,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_powers; } 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_powers; } 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_powers; } /* Reset the switch through internal reset */ @@ -2527,7 +2529,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_powers; /* Check for PHY muxing on port 5 */ if (dsa_is_unused_port(ds, 5)) { @@ -2554,7 +2556,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_powers; } id = of_mdio_parse_addr(ds->dev, phy_node); if (id == 0) @@ -2579,16 +2581,24 @@ mt7530_setup(struct dsa_switch *ds) if (of_property_read_bool(priv->dev->of_node, "gpio-controller")) { ret = mt7530_setup_gpio(priv); if (ret) - return ret; + goto err_powers; } #endif /* CONFIG_GPIOLIB */ /* Flush the FDB table */ ret = mt7530_fdb_cmd(priv, MT7530_FDB_FLUSH, NULL); if (ret < 0) - return ret; + goto err_powers; return 0; + +err_powers: + if (priv->id == ID_MT7530) + regulator_disable(priv->io_pwr); +err_disable_core_pwr: + if (priv->id == ID_MT7530) + regulator_disable(priv->core_pwr); + return ret; } static int -- 2.50.1.windows.1