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 Reviewed-by: Andrew Lunn --- 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 e784123fb79c..1ae0ca278969 100644 --- a/drivers/net/dsa/mt7530.c +++ b/drivers/net/dsa/mt7530.c @@ -2444,6 +2444,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; } } @@ -2466,20 +2467,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 */ @@ -2546,7 +2549,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)) { @@ -2573,7 +2576,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) @@ -2597,17 +2600,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