Re: [PATCH v2] net: dsa: mt7530: disable the power rails on setup failure

From: Andrew Lunn

Date: Mon Nov 23 2026 - 16:41:38 EST


On Mon, Nov 23, 2026 at 07:09:13PM +0800, Haoran Wang wrote:
> mt7530_setup() enables the core and io regulators, but only
> mt7530_remove() disables them. A failed probe never reaches .remove(),
> so the rails stay enabled on every setup failure path, and the regulator
> core warns when devres later puts an enabled regulator. The common case
> is mt7530_setup_irq() returning -EPROBE_DEFER, where each re-probe
> enables the rails again.
>
> Tie the regulator lifetime to the switch setup/teardown pair. Disable the
> rails in mt753x_teardown() and on the mt753x_setup() error paths after
> sw_setup() succeeds, and drop the now-redundant disables from
> mt7530_remove(). This also avoids an unbalanced disable when a switch in
> a multi-switch tree fails setup while already bound. Move
> mt7530_setup_gpio() after the FDB flush so the gpiochip is not left
> registered when the rails are dropped.
>
> Signed-off-by: Haoran Wang <wanghr2026@xxxxxxxxxxxxxxxxxx>

Please break this patch up into lots of small patches, with good
commit messages, which are obviously correct.

taerdown is the opposite of setup. So do that code movement as one
patch.

Then add patches to fix the missing error handling.

> - 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);
> - }

This prints error messages when things go wrong.

> +static void
> +mt7530_disable_pwrs(struct mt7530_priv *priv)
> +{
> + if (priv->id != ID_MT7530)
> + return;
> +
> + regulator_disable(priv->core_pwr);
> + regulator_disable(priv->io_pwr);

This does not. Why? If you add this helper as a little patch, you can
explain in the commit message why you decided to throw away the error
messages.

> + /* Flush the FDB table */
> + ret = mt7530_fdb_cmd(priv, MT7530_FDB_FLUSH, NULL);
> + if (ret < 0)
> + 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 */
>
> - /* Flush the FDB table */
> - ret = mt7530_fdb_cmd(priv, MT7530_FDB_FLUSH, NULL);
> - if (ret < 0)
> - return ret;

This move should be one patch, and the commit message explaining why.

> +
> +err_disable_pwrs:
> + mt7530_disable_pwrs(priv);
> +
> + return ret;
> +
> +err_disable_core_pwr:
> + if (priv->id == ID_MT7530)
> + regulator_disable(priv->core_pwr);
> +
> + return ret;

Having two error cleanup blocks of code with a return is very
unusual. Look at other cleanup blocks. How often do you see this?
Please make it have just one return statement.

> - if (ret && priv->irq_domain)
> - mt7530_free_mdio_irq(priv);
> + if (ret) {
> + if (priv->irq_domain)
> + mt7530_free_mdio_irq(priv);
> + goto err_disable_pwrs;
> + }

Since you are adding error cleanup at the end of the function, move
this to the end as well.

Andrew

---
pw-bot: cr