🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #20328

Re: [PATCH] net: dsa: mt7530: fix regulator leak in mt7530_setup()

#20328
From: netdev-bot+sashiko
Date: Sun, 22 Nov 2026 02:06
184 lines
13909 bytes
Thank you for your contribution! Sashiko AI review found 3 potential
issue(s) to consider.

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

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 err_powers/err_disable_core_pwr paths in
  mt7530_setup() disable core_pwr/io_pwr, but mt7530_remove() was not…
- [Low] This is speculative and depends on the hardware.

--

net: dsa: mt7530: fix regulator leak in mt7530_setup()

This commit adds two error labels to mt7530_setup(). Error paths taken
after the core and io regulators are enabled now disable them again. The
common cleanup is guarded by a priv->id == ID_MT7530 check because MT7621
shares the sw_setup callback but never enables the regulators.

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

[ ... ]

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

[Severity: High]
Is this fix complete? mt7530_setup() is only the sw_setup callback. On
success it returns 0 with both core_pwr and io_pwr enabled.

The real ds->ops->setup is mt753x_setup(), and it can still fail after
that without disabling either supply:

drivers/net/dsa/mt7530.c:mt753x_setup() {
	int ret = priv->info->sw_setup(ds);
	...
	ret = mt7530_setup_irq(priv);
	if (ret)
		return ret;

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

mt7530_setup_irq() can return -EPROBE_DEFER from of_irq_get(), or fail in
devm_regmap_add_irq_chip_fwnode(). mt7530_setup_mdio() can fail in
devm_mdiobus_alloc() or devm_of_mdiobus_register(), and the latter can
also defer.

Later failures in the DSA core are not covered either. These include
dsa_switch_setup_tag_protocol(), user MII bus registration, and
dsa_tree_setup_ports/conduit/lags in dsa_tree_setup(). Those paths call
ds->ops->teardown, but mt753x_teardown() only cancels stats_work.

In all of these cases dsa_register_switch() fails and mt7530_probe()
returns the error. That means mt7530_remove() never runs, and it holds
the only matching regulator_disable() calls.

The devm regulator handles are then released with a non-zero
enable_count, which hits this warning:

drivers/regulator/core.c:_regulator_put() {
	/* Docs say you must disable before calling regulator_put() */
	WARN_ON(regulator->enable_count);
	...
}

The provider's use_count is also never dropped. Each -EPROBE_DEFER retry
enables the supplies again with a new handle, so the count keeps growing
and the switch stays powered and out of reset with no driver bound.

Would it work better to move ownership of the regulators? For example,
probe could enable them and register a devm action to disable them.
Another option is to unwind in mt753x_setup() and mt753x_teardown() and
change mt7530_remove() to match.

> +
> +err_disable_core_pwr:
> +	regulator_disable(priv->core_pwr);
> +	return ret;
> +
> +err_powers:
> +	if (priv->id == ID_MT7530) {
> +		regulator_disable(priv->io_pwr);
> +		regulator_disable(priv->core_pwr);
> +	}

[Severity: Medium]
Can this leave mt7530_remove() disabling the regulators a second time?
mt7530_remove() was not changed, and it still disables both supplies
unconditionally:

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

Consider a multi-switch DSA tree where the MT7530 probes first.
dsa_tree_setup() returns 0 while the tree is incomplete:

net/dsa/dsa.c:dsa_tree_setup() {
	...
	complete = dsa_tree_setup_routing_table(dst);
	if (!complete)
		return 0;
	...
}

So the MT7530 driver binds before ops->setup has run. When the last
switch of the tree probes, mt753x_setup()->mt7530_setup() runs for the
MT7530 that is already bound.

If mt7530_setup() then fails, err_powers drops the consumer enable_count
to zero. The error goes back to the other switch's probe, and the MT7530
stays bound.

On a later unbind, mt7530_remove() calls regulator_disable() again. That
triggers the "unbalanced disables for %s" WARN in _regulator_disable(),
which returns -EIO. The driver also logs "Failed to disable core power"
and "Failed to disable io pwr".

Before this patch, a failed setup left the regulators enabled, so the
remove path was balanced.

[Severity: Low]
This one is speculative and depends on the hardware, but should the chip
be put back into reset before the supplies are cut here? Every goto
err_powers happens after mt7530_setup() has already released reset:

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

err_powers only disables io_pwr and core_pwr. Suppose the reset GPIO is
present and the supplies really turn off. The SoC would then keep driving
the reset input at its run level into an unpowered chip, which could
back-power it through the input protection diodes.

mt7530_remove() already disables the regulators in the same order. This
error path is new code, though, and could assert reset first.

> +	return ret;
>  }

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261118014114.1855-1-laixiangwu%40cmss.chinamobile.com
Technical Details
Message-ID: <179531318026.3135.909782780821579093@kernel.org>
Path: mbox-mo1.pugleaf.net!news-sfo.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-368565-linux-kernel-netdev=dewy.ru
References: <20261118014114.1855-1-laixiangwu@cmss.chinamobile.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-sfo.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-368565-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH] net: dsa: mt7530: fix regulator leak in mt7530_setup()
Date: Sun, 22 Nov 2026 02:06:20 +0000
Organization: Usenet Network
Message-ID: <179531318026.3135.909782780821579093@kernel.org>
References: <20261118014114.1855-1-laixiangwu@cmss.chinamobile.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="3547042"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:R/ix60EsIrrm+lwm8voTEZd4bN8= sha256:/+0xh1WQpOvPJDrmFtUGkiGYC2WBkuP1EIz66mRAbtE=
	sha1:y7JMF8JxTVP6SLjq3cc0WhiKtIA= sha256:0jE4VhSQwDHWcbpXcsN+rOcqWVdoD1Ed1raCDbP5/Gg=
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 CF65B115C66; Sun, 22 Nov 2026 05:06:48 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.4
X-Spam-Status: No, score=-3.4 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, URIBL_BLOCKED=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 TeODsxocYWSa;
	Sun, 22 Nov 2026 05:06:45 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-368565-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 sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id 90815115C56; Sun, 22 Nov 2026 05:06:30 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sea.lore.kernel.org (Postfix) with ESMTP id 957BD2FE48; Sun, 22 Nov 2026 02:06:27 +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=1795313187;
	b=DUuKEkt6BCprNCe4ALtQDEYa8DPGEKJUev2N2v6GxrZ+GNtZXc8n5MHtFC9v3U1GPrel
	 +7JqGfT+2+wufemObLUhhaL1E3c9+IxHjkTuyZHFhgS7PmYJc02Rzr89DDGlYR4z0C0L6
	 AWxyId7XobX+g00YWUpuEH+nhYuft9MlfqAS22BZWcCVdlkClqcTZFs0/3NX8TVlVwh+R
	 yuf1Sv0/uW8yC913hkec5GOe4aL3E98QyRXsC+mzSHxVz9qF7n5LOc66OTVaNkjJ/buNw
	 TIR5bmj6FGps2e81hEzDIQZMNsWRUEQic8N5535Lf56zTH7+vyato1wQTwYEpeJDH9g==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795313187;
	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=dEnkapeRnfFV6E+zu66FrpGD/YUjf1f+f1RLCOGBPoI=;
	b=PJ/To4qIAzemdbXxHaAICt4d7JILE7Q3zzpu92R+SAJ5leXQjC3z3RrqB65dazurJpGI
	 icChoSlShjk90xKTnkQYCjfjjNcIPhhG/JVFnpDDEoMJRJx1tk5/paFXB1WHlvs+wn2vK
	 L36x/swD+eH0M+cWFj53cDqc2+sMH8yEE3cDceFClfFKnEGXfuZoAUPqRpwuEmlFuxtD9
	 wdXUeMUP9UyTJK5txPO3pfRr2l9cBaZ6/ruxYOmb/dUcGWm6AebpiPrWuxIhlygysEyki
	 Zb36r7nFd/PpAo/bO70ng6Q+K0lma6nl5jnahRSPlVrMRQfLrpY0UZ566Hewp6KAH3g==
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=YalRjlxg;
	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 6EE7B606A331;
	Sun, 22 Nov 2026 02:06:27 +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=YalRjlxg
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=1795313181;
	b=W6XFIGsRITHrcDnCrv6KZVM+7MJrVYQf8nf9AFRces3I1sVCCQqSzQE7/AB0Uu3Ctw1n
	 oJgHLTQ+aJdIRNlA4z5szAKh8wrLPKfgUoLlf0bOAXISxO3sTIfyJVU7oi/gXjgDfk6tj
	 bh9FGmzPeDaNJUbqqPKw3LMjdKocUtsJjEi6ZaYtPKasvlJCkBQhiophcHv7YLWmniCIU
	 JykflEarfN8Lz4Vir/0lwUhs9BY878WDriSzT3mPDmeJxjEqk0zAG+ssaNITxEQABv6LO
	 aZhRZibFvGpySXDOg6Ey3wHALbPXst6gMi1clgvGYkoDuPRBOxjkIsZeCPUDD/yJqBQ==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795313181;
	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=dEnkapeRnfFV6E+zu66FrpGD/YUjf1f+f1RLCOGBPoI=;
	b=p2up024baxH4F2s9llTVx1Vy0yxQ2DQjCOKM6JJkIChCkmBvxNZMQd7WhP+Q3mT8DC1z
	 Af3myXVLCo70kzHhHlHQ/+XrM9dzNYZNXzftGyEjMeRS78weQiQDHWozMP+1qGBf83qfH
	 JqiBJ93tPn1S0U1lZs1EaWEf6cSgoOS4Gl1ht+xbvNmqikBY/5p9pbFLmXQ1TlF9/2P87
	 MuHLSRvcHLSoZQOd4zVBGomnQpzy8JsbPZw4yJI+TcSLVppwkW47k2vJpHg+SH1zp0E+3
	 bWFhV9s0RTndyZhVq55gVRiiON05FVKTh1uFIf89n+Jg9aWRuELTE31S//S1MXgmClg==
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=YalRjlxg;
	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 8BADE606A320;
	Sun, 22 Nov 2026 02:06:21 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id A81B01F000C0;
	Sun, 22 Nov 2026 02:06:20 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1795313181;
	bh=dEnkapeRnfFV6E+zu66FrpGD/YUjf1f+f1RLCOGBPoI=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=YalRjlxg68ljOxtTlXXmOhV7A1JdPSwzk9wrbMR8QTpe8ZaOHGWUTzwTYHfuJvIiA
	 3z3KPYEPKX3Vb1Py0Po6ypLvmwv+DeTD4BskXbZZywwjegjgfcsMw3rpFGaqnxemTW
	 83hSLPMiJA6q9LuSUuDj0XXvg37GBjuvpWyzJYTTzMPz6E1coIyzMmf0rICthhogB2
	 5i9mpj6w65W+Gw6DIAUIxXOBSFc0ApOReUZdEoE09U0u7YO5pbxVYRU/WmUwQOf0TB
	 ah7Flze1QxI7FqGwhZOnITb2bbBzGPQM+T2inpA6TFq1hXVxuUyvBVDmTKlzsucrV+
	 oRWrXKQAyigOw==
X-Cc: chester.a.unal@arinc9.com, daniel@makrotopia.org, andrew@lunn.ch,
 olteanv@gmail.com, sean.wang@mediatek.com, netdev@vger.kernel.org,
 linux-kernel@vger.kernel.org, kuba@kernel.org
X-In-Reply-To: <20261118014114.1855-1-laixiangwu@cmss.chinamobile.com>
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