From: Andrew Lunn <andrew@lunn.ch>
To: Haoran Wang <wanghr2026@mail.zgclab.edu.cn>
Cc: chester.a.unal@arinc9.com, daniel@makrotopia.org,
olteanv@gmail.com, davem@davemloft.net, edumazet@kernel.org,
kuba@kernel.org, pabeni@redhat.com, matthias.bgg@gmail.com,
angelogioacchino.delregno@collabora.com, netdev@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] net: dsa: mt7530: disable the power rails on setup failure
Date: Mon, 23 Nov 2026 22:40:59 +0100 [thread overview]
Message-ID: <66d0cc53-b1e9-4c5d-adcd-ac752c21e3fe@lunn.ch> (raw)
In-Reply-To: <179543215348.11880.18316180385674365789@mail.zgclab.edu.cn>
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@mail.zgclab.edu.cn>
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
prev parent reply other threads:[~2026-11-23 21:41 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-23 11:09 Haoran Wang
2026-11-23 11:12 ` netdev-bot+sinfo
2026-11-23 11:24 ` 王浩然
2026-11-23 21:40 ` Andrew Lunn [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=66d0cc53-b1e9-4c5d-adcd-ac752c21e3fe@lunn.ch \
--to=andrew@lunn.ch \
--cc=angelogioacchino.delregno@collabora.com \
--cc=chester.a.unal@arinc9.com \
--cc=daniel@makrotopia.org \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mediatek@lists.infradead.org \
--cc=matthias.bgg@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=olteanv@gmail.com \
--cc=pabeni@redhat.com \
--cc=wanghr2026@mail.zgclab.edu.cn \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®