Linux-mediatek Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: wanghr2026@mail.zgclab.edu.cn
Cc: chester.a.unal@arinc9.com, daniel@makrotopia.org, andrew@lunn.ch,
	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: Tue, 24 Nov 2026 12:05:56 +0000	[thread overview]
Message-ID: <179552195677.3135.2679930645626053258@kernel.org> (raw)
In-Reply-To: <179543215348.11880.18316180385674365789@mail.zgclab.edu.cn>

Thank you for your contribution! Sashiko AI review found 3 potential
issue(s) to consider.

Critical: 0 · High: 1 · Medium: 0 · Low: 2

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [High] The commit message says moving mt7530_setup_gpio() after the FDB
  flush means "the gpiochip is not left registered when the rails are…
- [Low] The patch fixes a runtime bug: regulators stay enabled on
  mt7530_setup()/mt753x_setup() failure, enable_count grows on each…
- [Low] The new power-down helper mt7530_disable_pwrs() drops core_pwr
  and io_pwr without first asserting the chip reset.

--

net: dsa: mt7530: disable the power rails on setup failure

This patch moves the MT7530 core/io regulator disable out of
mt7530_remove(). The rails are now disabled in mt753x_teardown() and on
the mt7530_setup()/mt753x_setup() error paths. It also moves
mt7530_setup_gpio() after the FDB flush in mt7530_setup().

> Signed-off-by: Haoran Wang <wanghr2026@mail.zgclab.edu.cn>

[Severity: Low]

This fixes a regulator core WARN and an unbalanced regulator_disable() in
mt7530_remove(), but there is no Fixes: tag.

git blame shows that the regulator_enable() calls in mt7530_setup(), with
their bare return ret error paths, come from:

ddda1ac116c8 ("net: dsa: mt7530: support the 7530 switch on the Mediatek MT7621 SoC")

That commit restructured code first added in:

b8f126a8d543 ("net-next: dsa: add dsa support for Mediatek MT7530 switch")

Should one of these be added as a Fixes: tag? The recent fix to the same
regulator handling, c2cdef41e0b4 ("net: dsa: mt7530: fix NULL dereference
on unbind of MT7531 and MT7621"), carries one.

> diff --git a/drivers/net/dsa/mt7530.c b/drivers/net/dsa/mt7530.c
> index d5a199293f78a..5bbeed0491c45 100644
> --- a/drivers/net/dsa/mt7530.c
> +++ b/drivers/net/dsa/mt7530.c
> @@ -2376,6 +2376,16 @@ mt7530_setup_mdio(struct mt7530_priv *priv)
>  	return ret;
>  }
>  
> +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);
> +}

[Severity: Low]

Should reset be asserted here before the rails are dropped?

mt7530_probe() requests the reset GPIO with GPIOD_OUT_LOW, so reset is
asserted while the chip is unpowered. mt7530_setup() then pulses reset and
leaves it deasserted:

	gpiod_set_value_cansleep(priv->reset, 0);
	usleep_range(5000, 5100);
	gpiod_set_value_cansleep(priv->reset, 1);

Every new caller of mt7530_disable_pwrs() cuts io_pwr and core_pwr with
reset still deasserted. That covers the err_disable_pwrs labels in
mt7530_setup() after the reset pulse, the mt753x_setup() error paths, and
mt753x_teardown().

The SoC then keeps driving the inactive level into the RESET pad of a chip
whose IO rail is off, and this repeats on every -EPROBE_DEFER re-probe.
The MCM path also never calls reset_control_assert() before power-off.

The v2 notes say this was left out because it matches the old
mt7530_remove() ordering. However, this patch adds several new power-down
points. Would asserting reset first, then disabling io_pwr and core_pwr,
better mirror the power-up sequence?

[ ... ]

> @@ -3205,11 +3228,11 @@ mt753x_setup(struct dsa_switch *ds)
>  
>  	ret = mt7530_setup_irq(priv);
>  	if (ret)
> -		return ret;
> +		goto err_disable_pwrs;
>  
>  	ret = mt7530_setup_mdio(priv);
>  	if (ret)
> -		return ret;
> +		goto err_disable_pwrs;

[Severity: High]

The commit message says:

  Move mt7530_setup_gpio() after the FDB flush so the gpiochip is not left
  registered when the rails are dropped.

and the v2 notes say "no failure path leaves the gpiochip registered after
the rails are disabled". Does that hold on these paths?

mt7530_setup_gpio() is now the last step of mt7530_setup(), so the reorder
only covers the FDB flush failure. When mt7530_setup_irq() fails here, for
example with -EPROBE_DEFER from of_irq_get(), the gpiochip is already
registered through devm:

mt7530_setup_gpio() {
    ...
    return devm_gpiochip_add_data(dev, gc, priv);
}

err_disable_pwrs then calls mt7530_disable_pwrs() while the gpiochip is
still registered. The commit message calls -EPROBE_DEFER the common case.

On the mt7530_setup_mdio() failure path, mt7530_setup_irq() has also
already registered the regmap IRQ chip and its threaded handler:

	ret = devm_regmap_add_irq_chip_fwnode(dev, dev_fwnode(dev),
					      priv->regmap, irq,
					      IRQF_ONESHOT,
					      0, &mt7530_regmap_irq_chip,
					      &irq_data);

The new mt7530_disable_pwrs() call in mt753x_teardown() has the same
problem. DSA calls teardown from the teardown label in dsa_switch_setup()
when tag protocol or user MDIO bus setup fails. It also runs on any tree
teardown, through:

dsa_tree_teardown()->dsa_tree_teardown_switches()->dsa_switch_teardown()

In all of these cases three resources stay registered while the rails are
cut: the gpiochip, the regmap IRQ chip, and the internal MDIO bus from
devm_of_mdiobus_register(). Their lifetime is tied to device bind, not to
DSA setup/teardown.

In a multi-switch tree, unbinding another switch tears this switch down
while it stays bound. The registered-but-unpowered state then lasts for as
long as this switch stays bound. Before this patch the rails stayed on in
these cases.

Can a gpiochip consumer (mt7530_gpio_get(), mt7530_gpio_set() and the
direction callbacks), the regmap-irq threaded handler, or a PHY on the MDIO
bus then issue regmap/MDIO accesses to an unpowered chip?

Would this need explicit unregistration in teardown and on these error
paths, using non-devm registration or the devm_*_release helpers, instead
of the reorder? If not, could the commit message and the v2 notes be
corrected?

[ ... ]

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/179543215348.11880.18316180385674365789%40mail.zgclab.edu.cn


      parent reply	other threads:[~2026-11-24 12:06 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-23 11:09 [PATCH v2] net: dsa: mt7530: disable the power rails on setup failure Haoran Wang
2026-11-23 11:12 ` netdev-bot+sinfo
2026-11-23 11:24   ` 王浩然
2026-11-23 21:40 ` Andrew Lunn
2026-11-24 12:05 ` netdev-bot+sashiko [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=179552195677.3135.2679930645626053258@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=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