🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #20809

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

#20809
From: netdev-bot+sashiko
Date: Mon, 23 Nov 2026 08:26
198 lines
15007 bytes
Thank you for your contribution! Sashiko AI review found 4 potential
issue(s) to consider.

Critical: 0 · High: 1 · Medium: 1 · 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 fix is incomplete.
- [Medium] The new error-path disable in mt7530_setup() can be followed
  by a second disable of the same rails, because mt7530_remove()…
- [Low] In mt7530_setup(), suppose mt7530_setup_gpio() has registered the
  GPIO chip with devm_gpiochip_add_data() and the later…
- [Low] Speculative.

--

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

This commit changes the early returns in mt7530_setup() that come after
the core and io regulator enables. They now jump to new unwind labels,
which disable io_pwr and core_pwr when priv->id == ID_MT7530. The goal is
to stop the switch rails from staying enabled after a failed probe.

> diff --git a/drivers/net/dsa/mt7530.c b/drivers/net/dsa/mt7530.c
> index d5a199293f78a..769f733f80d2a 100644
> --- a/drivers/net/dsa/mt7530.c
> +++ b/drivers/net/dsa/mt7530.c

[ ... ]

> @@ -2579,16 +2581,25 @@ 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_disable_pwrs;
>  	}
>  #endif /* CONFIG_GPIOLIB */
>  
>  	/* Flush the FDB table */
>  	ret = mt7530_fdb_cmd(priv, MT7530_FDB_FLUSH, NULL);
>  	if (ret < 0)
> -		return ret;
> +		goto err_disable_pwrs;

[Severity: Low]
Suppose mt7530_setup_gpio() has already registered the gpiochip with
devm_gpiochip_add_data() and the FDB flush then fails. This goto turns
off io_pwr and core_pwr while the gpiochip is still registered.

The gpiochip is only removed when devres on priv->dev is released. In a
single-switch tree that happens at the end of the failed probe. If another
switch's probe drove the tree setup and the MT7530 stays bound, it does
not happen at all.

During that window, could mt7530_gpio_get(), mt7530_gpio_set() and
mt7530_gpio_direction_*() do regmap accesses over MDIO to a switch whose
supplies are off? Should the gpiochip be removed before the hardware
loses power?

>  
>  	return 0;
> +
> +err_disable_pwrs:
> +	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;
>  }

[Severity: High]
Does this fully cover the leak described in the commit message? These
labels only handle failures inside mt7530_setup(). The rails can still be
left enabled when something fails after mt7530_setup() has returned 0.

mt753x_setup() calls priv->info->sw_setup(), which is mt7530_setup() for
ID_MT7530, and then does this:

drivers/net/dsa/mt7530.c:mt753x_setup() {
    ...
	ret = mt7530_setup_irq(priv);
	if (ret)
		return ret;

	ret = mt7530_setup_mdio(priv);
	if (ret)
		return ret;
    ...
}

mt7530_setup_irq() can fail with -EPROBE_DEFER from of_irq_get() when the
interrupt parent hasn't probed yet. Neither of these returns disables
core_pwr or io_pwr.

Something similar happens in dsa_switch_setup() and dsa_tree_setup().
Failures after ds->ops->setup() succeeds (tag protocol setup, user MDIO
bus, ports, conduit, lags) only unwind through ds->ops->teardown, which is
mt753x_teardown():

static void
mt753x_teardown(struct dsa_switch *ds)
{
	struct mt7530_priv *priv = ds->priv;

	if (priv->bus)
		cancel_delayed_work_sync(&priv->stats_work);
}

In all of these cases dsa_register_switch() fails, so mt7530_probe() fails
and mt7530_remove() never runs. When devres later calls regulator_put(),
the regulator core would hit WARN_ON(regulator->enable_count). On
-EPROBE_DEFER, every re-probe enables the rails again:

mt7530_probe()
  dsa_register_switch()
    dsa_tree_setup()
      dsa_switch_setup()
        mt753x_setup()
          mt7530_setup()       <- rails enabled, returns 0
          mt7530_setup_irq()   <- -EPROBE_DEFER, rails left enabled

Would it be better to tie the regulator lifetime to the whole
setup/teardown pair instead of using local labels in mt7530_setup()? One
option is to disable the rails in mt753x_teardown() and on the
mt753x_setup() error paths, and change mt7530_remove() to match. Another
is to use devm-managed enables.

[Severity: Medium]
Can these new disables lead to unbalanced regulator disables later in
mt7530_remove()?

mt7530_remove() in drivers/net/dsa/mt7530-mdio.c disables both rails
whenever priv->id == ID_MT7530. It does not know whether setup succeeded:

drivers/net/dsa/mt7530-mdio.c:mt7530_remove() {
    ...
	if (priv->id == ID_MT7530) {
		ret = regulator_disable(priv->core_pwr);
		...
		ret = regulator_disable(priv->io_pwr);
    ...
}

The driver supports port 5 as a DSA link (see the
dsa_is_dsa_port(priv->ds, 5) check in mt7530_setup_port5()). In a
multi-switch tree, dsa_tree_setup() returns 0 while the tree is
incomplete:

	complete = dsa_tree_setup_routing_table(dst);
	if (!complete)
		return 0;

So mt7530_probe() can succeed, and mt7530_setup() then runs later from
another switch's dsa_register_switch(). Suppose it fails there after the
rails are enabled. These labels bring the enable counts back to 0, and the
error goes to the other switch's probe. The MT7530 stays bound with its
drvdata set.

On a later unbind, mt7530_remove() would call regulator_disable() again.
_regulator_disable() would then WARN with "unbalanced disables" and return
-EIO. Before this patch the rails stayed enabled after a setup failure, so
remove was balanced in this case.

[Severity: Low]
This one is speculative: should the switch be put back into reset before
the rails are dropped here? By the time any of these gotos run, the chip
has already been taken out of reset earlier in mt7530_setup():

	if (priv->mcm) {
		reset_control_assert(priv->rstc);
		usleep_range(5000, 5100);
		reset_control_deassert(priv->rstc);
	} else {
		gpiod_set_value_cansleep(priv->reset, 0);
		usleep_range(5000, 5100);
		gpiod_set_value_cansleep(priv->reset, 1);
	}

On the non-MCM path, the host keeps driving the reset GPIO at its run
level, and the MDIO controller keeps driving MDC/MDIO, into a chip whose
supplies have just been released. On boards where regulator_disable()
actually removes the rail, could that back-power the I/O domain?

Asserting reset with gpiod_set_value_cansleep(priv->reset, 0) or
reset_control_assert(priv->rstc) before the regulator_disable() calls
would avoid this. mt7530_remove() has the same ordering, but this patch
adds a new power-off sequence that is reached more often.

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/1795076103951-10-8fa23d94%40mail.zgclab.edu.cn
Technical Details
Message-ID: <179542236717.3135.17350424891277003723@kernel.org>
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-369142-linux-kernel-netdev=dewy.ru
References: <1795076103951-10-8fa23d94@mail.zgclab.edu.cn>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-369142-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH] net: dsa: mt7530: disable the power rails on setup failure
Date: Mon, 23 Nov 2026 08:26:07 +0000
Organization: Usenet Network
Message-ID: <179542236717.3135.17350424891277003723@kernel.org>
References: <1795076103951-10-8fa23d94@mail.zgclab.edu.cn>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="3825751"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:2eoMDTLww4/xmos4k9pC89bFUNg= sha256:QwLvUc2g6inlIqY5i1KN0EaRn6Km7BEESqH04jp6a64=
	sha1:FDGfiNNwpy9pxf5D8mOZN5dnwFI= sha256:43X/7IjgtIvzc6y3AWoT//FxizZW1+bgzhy2F+mrg5Q=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id 43FCE125D97; Mon, 23 Nov 2026 11:26:31 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.401
X-Spam-Status: No, score=-3.401 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1,
	DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,
	MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
	SPF_PASS=-0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=kernel.org
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id wNrOcRvCbcY6;
	Mon, 23 Nov 2026 11:26:23 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-369142-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org
X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114])
	by mail.dewy.ru (Postfix) with ESMTPS id 0473B125D96; Mon, 23 Nov 2026 11:26:14 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by tor.lore.kernel.org (Postfix) with ESMTP id BBCBC23E52; Mon, 23 Nov 2026 08:26:12 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1795422370;
	b=Wv7UZSSKEYbwXy8qfVhWHDtjIGuT3JwaO4Mnt8JhElXuVr5bBWYXGe+O5PFKpKYm4Fmb
	 rHeGHnXBBEuap8xkkLtH0BpF3Y9+XHbf0VrxEkJOi1KtfkZN6hbapC/3Zv4Ng+aR9qGis
	 dD5aIoFup49t2pZE+HypvqpE6dSRwO9ZLnFHcIrOgbaUay1IQqMocs+6CST/deLxoa6ys
	 PmonV51zuRH4M9WGpamqTueQbtl3heQVIXdpbKVqTSWMn+12wsFL0lthRZA0coKF/bTmT
	 rymDp8iDkMmAe39EP0Is23LIU22t+v/hRWKqLJK/4GSeb5gjYnKt2t6Sm2samk/Jeqw==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795422370;
	h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc:
	 Date:Message-ID:In-Reply-To:References:X-sashiko-severity:
	 Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id:
	 List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner:
	 Precedence:MIME-Version;
	bh=2ZXYzpMsSpVMbq5bALXeiDcyDHaH4rSnY+t2qNogl3c=;
	b=HZvGuQiDUmjrHzfYg9AQoloZl2yE67ojSunjTYx0zW/2ZX7RMOluLK6MBg82qt7gbPdb
	 zE3vpYV82cYjd9hnkdtRNYsI3X8j7Vx42vyLMpHVE2Vf0wuv7WGQvd0qF36o8ehVrUylR
	 z2sTeablqLT5cqRjdPwGbrIcdiXf0KIpljvqLOvgdk39Z5nUS7W7d4oay3l8HIcxEmPkL
	 cV20KqZb8cCMAVZuq/TTFVal1CaIWSjO0p2iZtf78yeC0bd9xOZzUmHhdw/1vwPaDCr/b
	 dCL4SQIOuSl4Kl4Il1L2eh9yR/hlvd+vd2MBPV0drzFcaJc+z8xYt01lRVA4Ck1v+MA==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=hG9R1cT4;
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id 17C32606A32E;
	Mon, 23 Nov 2026 08:26:10 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=hG9R1cT4
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1795422369;
	b=ZNPC/mnJZYpFTYxiSt2V6mMn0KKBLkYLBTMeVkrYBPtuqShpxrHWE/KRgftwOADeNjWT
	 00v9LuD21V9msSOkhN4dDymyfTUHVQRAw+RKTU7cBXVwmdYP8tYygksV+q3WI4aC5UfaA
	 hgZFgQ1pGW5qUdV1dv8tgnsq1aLEcuZEQ6fK2x8O8T214G6Vc8Wf3zmKyMtB5VFhZP436
	 Ay68I3leOmHnYxWqrWtY4rEW4B2L2Glo+SG13ViwXDLK6w1QP6lOxEH36WPzVOrz4NJ9M
	 fmBzk6vC2qvscSYNOqitZuO7xX6ULUJ9vx959g+wmV4HEDcF/SPwgXWcudN9HwPMgqg==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795422369;
	h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID:
	 In-Reply-To:References:X-sashiko-severity:Content-Type:
	 Content-Transfer-Encoding:MIME-Version;
	bh=2ZXYzpMsSpVMbq5bALXeiDcyDHaH4rSnY+t2qNogl3c=;
	b=ADRVEGJUdiQ1KLOjKaz+GUxFvkezVZRz9NUZ4oO6O81GkwUTqxlo3/qhuQ/i6uV2do8t
	 lJJH9qdmyxi9agx/mm8/UXrj4Be+eJ4DTXg+Ngbl179BtrtZPhV5rcv7BQuz7nGbYXLzq
	 dgWpxuMIUcKmQ3VViUdOUjWXbXkAQPV3Cc/Gf+Fnt4ayoYvAGPZdtklv5xAHYjf8BYp8/
	 OnkNPiwPk9QT641SvsxoGwyx5Mc+njrAskZ9PNNo2iPFB6q6KBRPiDV2gY9YF7kmWETDV
	 w433GLgu4u7TQaRvLXPYQmRltBFv/kPtxOkEWRNBmYUXYEI60mdWo4N+cyou9EIn1sA==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=hG9R1cT4;
	arc=none smtp.remote-ip=100.103.45.18
X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 31E4B606A31A;
	Mon, 23 Nov 2026 08:26:08 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9BCE11F000C4;
	Mon, 23 Nov 2026 08:26:07 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1795422368;
	bh=2ZXYzpMsSpVMbq5bALXeiDcyDHaH4rSnY+t2qNogl3c=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=hG9R1cT4I778FIhn9+UnCNDcoR0RghBICzDHiYHixQahjyOswRk8B+/IIHceoKVmM
	 /xEmFoR8oJvHBtjGToResk/kU1fR8t3juUbfgppPOQ6nW5GD8iuYb4yDzoifl6rYJ2
	 uymziFFSfMMjkLVV1KUl+qCF7J2ZNfoVsfGezQHPjoblSSKWe6M5sodasfGgF9rJPP
	 /IG0CdLeds+JE05IIzItpNLvLNMBplTnue/NwuCXYhEn4+F4Ene3jV/1VjfPUPkT6M
	 9dwCHsG9RculA4+82o71pCuTDRcBzlFagnA5U3hYkT5oCYnez0mSU2N+hwNCqQB8wW
	 sQap6TZqvNlWQ==
X-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
X-In-Reply-To: <1795076103951-10-8fa23d94@mail.zgclab.edu.cn>
X-sashiko-severity: High
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list