🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #21456

[PATCH v4] net: dsa: mt7530: enable the regulators in probe() and unwind on error

#21456
From: Xiangwu Lai
Date: Tue, 24 Nov 2026 01:34
147 lines
14305 bytes
mt7530_setup() enables the core and io regulators of the MT7530, but the
only matching regulator_disable() calls live in mt7530_remove(), which
never runs when the probe fails.  A failure anywhere between the enables
and a fully registered switch - the remaining steps of mt7530_setup(),
the IRQ chip or MDIO bus registration in mt753x_setup() (both can also
return -EPROBE_DEFER), the SGMII PCS creation, or the DSA core itself -
therefore leaves both regulators enabled.  The devm-acquired handles
are then released with a non-zero enable_count, which triggers the
WARN_ON() in _regulator_put(), and each probe deferral grows the count
further.

Move the enables to mt7530_probe(), right after the regulators are
acquired, and unwind them with plain error labels if a later step in
the probe fails.  mt7530_setup() and mt7530_remove() keep their original
shape, so the enables and disables stay balanced in every combination of
probe, setup and unbind: a failed probe always unwinds, and a switch
that stays bound is always disabled exactly once by mt7530_remove().

Enabling the supplies this early is safe.  Nothing accesses the switch
between the enables and dsa_register_switch(): the reset line has been
asserted since it was acquired in mt7530_probe() with GPIOD_OUT_LOW, so
the rails come up while the chip is held in reset, and mt7530_setup()
still releases the reset afterwards, unchanged.  MT7621 does not have
these supplies and is skipped by the priv->id == ID_MT7530 guards, and
the MT7988 MMIO variant has no regulators at all.

Found by code inspection; the issue has not been triggered at runtime
and no MT7530 hardware was available for testing.  The in-tree boards
that wire these supplies (the MT7623 boards mt7623n-bananapi-bpi-r2
and mt7623n-rfb-emmc via mt7623a.dtsi) connect them to switchable
MT6323 PMIC outputs, so on those boards a failed probe would leave the
supplies on and trip the WARN_ON(enable_count) splat when the devm
handles are released.

Fixes: b8f126a8d543 ("net-next: dsa: add dsa support for Mediatek MT7530 switch")
Suggested-by: Andrew Lunn <andrew@lunn.ch>
Signed-off-by: Xiangwu Lai <laixiangwu@cmss.chinamobile.com>
---

Changes in v4:
- Drop the devm_add_action_or_reset() approach and unwind the regulators
  with plain error labels in mt7530_probe(), and restore the explicit
  disables in mt7530_remove(), as requested by Andrew Lunn.
- Extend the commit message: explain why enabling the regulators
  early in probe() is safe, and state which boards are affected.

Link: https://lore.kernel.org/r/20261123022415.433-1-laixiangwu@cmss.chinamobile.com

 drivers/net/dsa/mt7530-mdio.c | 38 ++++++++++++++++++++++++++++++++---
 drivers/net/dsa/mt7530.c      | 18 -----------------
 2 files changed, 35 insertions(+), 21 deletions(-)

diff --git a/drivers/net/dsa/mt7530-mdio.c b/drivers/net/dsa/mt7530-mdio.c
index 0be107dc6..b1daefc90 100644
--- a/drivers/net/dsa/mt7530-mdio.c
+++ b/drivers/net/dsa/mt7530-mdio.c
@@ -210,18 +210,50 @@ mt7530_probe(struct mdio_device *mdiodev)
 		priv->io_pwr = devm_regulator_get(&mdiodev->dev, "io");
 		if (IS_ERR(priv->io_pwr))
 			return PTR_ERR(priv->io_pwr);
+
+		regulator_set_voltage(priv->core_pwr, 1000000, 1000000);
+		ret = regulator_enable(priv->core_pwr);
+		if (ret < 0) {
+			dev_err(&mdiodev->dev,
+				"Failed to enable core power: %d\n", ret);
+			return ret;
+		}
+
+		regulator_set_voltage(priv->io_pwr, 3300000, 3300000);
+		ret = regulator_enable(priv->io_pwr);
+		if (ret < 0) {
+			dev_err(&mdiodev->dev,
+				"Failed to enable io pwr: %d\n", ret);
+			goto err_disable_core_pwr;
+		}
 	}
 
 	rc.lock_arg = &priv->bus->mdio_lock;
 	priv->regmap = devm_regmap_init(priv->dev, &mt7530_regmap_bus,
 					priv, &rc);
-	if (IS_ERR(priv->regmap))
-		return PTR_ERR(priv->regmap);
+	if (IS_ERR(priv->regmap)) {
+		ret = PTR_ERR(priv->regmap);
+		goto err_disable_powers;
+	}
 
 	if (priv->id == ID_MT7531)
 		priv->create_sgmii = mt7531_create_sgmii;
 
-	return dsa_register_switch(priv->ds);
+	ret = dsa_register_switch(priv->ds);
+	if (ret)
+		goto err_disable_powers;
+
+	return 0;
+
+err_disable_powers:
+	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;
 }
 
 static void
diff --git a/drivers/net/dsa/mt7530.c b/drivers/net/dsa/mt7530.c
index 7781a63b4..b669a94d4 100644
--- a/drivers/net/dsa/mt7530.c
+++ b/drivers/net/dsa/mt7530.c
@@ -2411,24 +2411,6 @@ mt7530_setup(struct dsa_switch *ds)
 	ds->ageing_time_min = 2 * 1000;
 	ds->ageing_time_max = (AGE_CNT_MAX + 1) * (AGE_UNIT_MAX + 1) * 1000;
 
-	if (priv->id == ID_MT7530) {
-		regulator_set_voltage(priv->core_pwr, 1000000, 1000000);
-		ret = regulator_enable(priv->core_pwr);
-		if (ret < 0) {
-			dev_err(priv->dev,
-				"Failed to enable core power: %d\n", ret);
-			return ret;
-		}
-
-		regulator_set_voltage(priv->io_pwr, 3300000, 3300000);
-		ret = regulator_enable(priv->io_pwr);
-		if (ret < 0) {
-			dev_err(priv->dev, "Failed to enable io pwr: %d\n",
-				ret);
-			return ret;
-		}
-	}
-
 	/* Reset whole chip through gpio pin or memory-mapped registers for
 	 * different type of hardware
 	 */
-- 
2.50.1.windows.1

Technical Details
Message-ID: <20261124013422.1408-1-laixiangwu@cmss.chinamobile.com>
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-369940-linux-kernel-netdev=dewy.ru

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-369940-linux-kernel-netdev=dewy.ru
From: laixiangwu@cmss.chinamobile.com (Xiangwu Lai)
Newsgroups: linux.kernel.netdev
Subject: [PATCH v4] net: dsa: mt7530: enable the regulators in probe() and
 unwind on error
Date: Tue, 24 Nov 2026 09:34:21 +0800
Organization: Usenet Network
Message-ID: <20261124013422.1408-1-laixiangwu@cmss.chinamobile.com>
MIME-Version: 1.0
Content-Transfer-Encoding: quoted-printable
Injection-Info: usenet.network;
	logging-data="4027244"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:0JOcZIyzJk8fshoEEr1jrP9FS4Y= sha256:9Sk6FfsV8gWejpkPGj3LJEg+qnP8pEa4/QSYnr1QCFM=
	sha1:g2iSKXeYx+fGfOTP2FouRWPBwZw= sha256:S9WDWzYCfeXWY2jlxoXe79KO5PzmQGh72KkB3QIXSSE=
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 6C5E1125DC9; Tue, 24 Nov 2026 04:34:52 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -2.75
X-Spam-Status: No, score=-2.75 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIM_INVALID=0.1, DKIM_SIGNED=0.1,
	HEADER_FROM_DIFFERENT_DOMAINS=0.249, 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=fail (1024-bit key)
	reason="fail (body has been altered)" header.d=cmss.chinamobile.com
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 G-yaCNV93QWi;
	Tue, 24 Nov 2026 04:34:48 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-369940-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=cmss.chinamobile.com
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id 50A13125DC6; Tue, 24 Nov 2026 04:34:40 +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 B741E32631; Tue, 24 Nov 2026 01:34:38 +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=1795484078;
	b=VV+K5w9+BTZoYbTB7nOeJdDK0PQC85xT/Vq4S5qb0sS+Fe4kXoJ7obFtk9IfzSEWgpKN
	 SG+h0/tz2G6dhRmzxNVw7uOr0C1iK1ZMSfW00450r8nQkji+sB48x9q5a87zGAdiIwX/s
	 5zL4wMSy6mlb3PtCklFfq/p2W2IPida5c2CMaPn8woXZhKDs2ms7WR0dnI0ThEx9HK6qL
	 kuy7muSpVNL0u48uIJss+byclLEoeZ8mXOx2aabYTca2nKTTi/2XFqi/qUw+b7/oOUvCz
	 S88IOzzuzL3F0VCaF5AQAsOsV5+4PbmN5jZWH1whdeWqYCfNIOF7O0g8J5PtACMltLA==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795484078;
	h=X-Original-To:Received:DMARC-Filter:DKIM-Signature:X-RM-TagInfo:
	 X-RM-SPAM-FLAG:Received:X-RM-TRANSID:X-RM-TagInfo:X-RM-SPAM-FLAG:
	 Received:X-RM-TRANSID:From:To:Cc:Subject:Date:Message-ID:X-Mailer:
	 X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe:
	 List-Unsubscribe:List-Owner:Precedence:MIME-Version:
	 Content-Transfer-Encoding;
	bh=oB91cvLVv77J9+Q8wIXKUGWmJ4awD5QCFhfn5x2IOY4=;
	b=guWrxOdDzQWlTJylisO4M+LP95WoT7ol6gmMK+2+z6OQbklHlrH2nV6gNesRYmmSOWpu
	 x99Oay+3s6GlI5wBDe0V4g7fRhoHH+FldqLxPPc0L1OOnAWSlDgXVQC6nRc5E2CcK8PrR
	 QyvU/YdbvqwLynPGXW5iLMwe7MLrJvNYD9H77z0rge8QwzTj0tEbfayarfZC2/O2rWvkU
	 sUS/kNqZk1UxE2G+fRRAPdyGwTdZw8uVwbW1Iy171SYF4yWgV755kyhDBQJk+YKWsfWw9
	 URA0NGq4eRczUhHaSWCy2VH1saN7HEHYTdX8RdQk+Q4eOZTYQNPZkkiZrQR89boNj/g==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=cmss.chinamobile.com header.i=@cmss.chinamobile.com header.a=rsa-sha256 header.s=default header.b=D92YFggw;
	dmarc=pass header.from=cmss.chinamobile.com;
	spf=pass smtp.mailfrom=cmss.chinamobile.com;
	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 8DB10606A32C;
	Tue, 24 Nov 2026 01:34:38 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (1024-bit key) header.d=cmss.chinamobile.com header.i=@cmss.chinamobile.com header.a=rsa-sha256 header.s=default header.b=D92YFggw
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=111.22.67.139
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1795484072;
	b=awaj7VdWOIm2VTlHE0WM3c2o4VQRCys3BJUKnO7UEbm8K7OhBDqDa1WBcu2KNawdZBjn
	 RZAhEMhI0FJoQophnt4zgnpcw29H4uROvG+v9I7Cc7ZwwJ7di1ScGb1PL2yiiB1X20y8/
	 D4RswXVUPdJTubK1krmiGD5y+4c1+FSyiucxoe4hv/Vjw0AlKdaBujdO4d/GJPClL5GT7
	 tOuU1LK0s/ReNY1dnNJfGkw/WjjkkiKg/4w4rj/B866hyMTDIsKng+qynUnf+q6mfGbiA
	 oqdR/263k1Xe2Q9fpTwL2wsndXAzm4Nxmc/rLoX3yJzZy2ide9iAc874Ia56aTDqQUA==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795484072;
	h=DMARC-Filter:DKIM-Signature:X-RM-TagInfo:X-RM-SPAM-FLAG:Received:
	 X-RM-TRANSID:X-RM-TagInfo:X-RM-SPAM-FLAG:Received:X-RM-TRANSID:From:
	 To:Cc:Subject:Date:Message-ID:X-Mailer:MIME-Version:
	 Content-Transfer-Encoding;
	bh=oB91cvLVv77J9+Q8wIXKUGWmJ4awD5QCFhfn5x2IOY4=;
	b=Ktc0zQcWzMGtFoLkO9PfxaoUNc9evJrs+IkxkZcLdCXhkm2aONqVmCr7M5StujYl5APg
	 7NZVktJFlD96KxkRVWO6xOJKJhme7+MpGJS0cczzZFCDjTrcyRQQ2mlicG3E16HdtLamJ
	 GiO1uiew6RFNx4d5Dm93F/WMjQm8Aq09AwMffDBSAoeHHewu5hnuqURIrmyrptRJXHAZj
	 9XPkxa2VPioLthcODQUT1inwjNjUpX1BlSjN+mMm3BaENdglB/dR5cJQMTzSexs9O15Is
	 sFvOXDkU9wb3Wwz+JzWQJoajSxepBpGsJQ3A5bpEFu4YFkJqRBeCRp1lkRDNaKHUDIg==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dmarc=pass header.from=cmss.chinamobile.com;
	spf=pass smtp.mailfrom=cmss.chinamobile.com;
	dkim=pass header.d=cmss.chinamobile.com header.i=@cmss.chinamobile.com header.a=rsa-sha256 header.s=default header.b=D92YFggw;
	arc=none smtp.remote-ip=111.22.67.139
X-Received: from cmccmta6.chinamobile.com (cmccmta6.chinamobile.com [111.22.67.139])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id 5BB37606A322;
	Tue, 24 Nov 2026 01:34:30 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 5BB37606A322
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=cmss.chinamobile.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=cmss.chinamobile.com
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
	d=cmss.chinamobile.com; s=default; l=0;
	h=from:subject:message-id:to:cc:mime-version;
	bh=47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=;
	b=D92YFggwGQGjrgPVGdskHxrKIIwlhRMut53NQc7gUWDTrK8T8iwti0gwOrLQd+H6zLlOsoqf/Dgvj
	 mekEyQPcl8zusaOfEMOGqZn7E+FqNq23zc+YhN9sggUcYEnl1QSx2mO3KWmxzAUlhJxFMv9Bpy89Hg
	 m1KhVoQJ83AwBdpY=
X-RM-TagInfo: emlType=0                                       
X-RM-SPAM-FLAG: 00000000
X-Received: from spf.mail.chinamobile.com (unknown[10.188.0.87])
	by rmmx-syy-dmz-app01-12001 (RichMail) with SMTP id 2ee16b04e99fc52-1d9e1;
	Tue, 24 Nov 2026 09:34:24 +0800 (CST)
X-RM-TRANSID: 2ee16b04e99fc52-1d9e1
X-RM-TagInfo: emlType=0                                       
X-RM-SPAM-FLAG: 00000000
X-Received: from DESKTOP-3K8GUTQ (unknown[223.108.79.98])
	by rmsmtp-syy-appsvr04-12004 (RichMail) with SMTP id 2ee46b04e99cf57-0e044;
	Tue, 24 Nov 2026 09:34:23 +0800 (CST)
X-RM-TRANSID: 2ee46b04e99cf57-0e044
X-Cc: daniel@makrotopia.org,
	andrew@lunn.ch,
	olteanv@gmail.com,
	sean.wang@mediatek.com,
	netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	netdev-bot+sashiko@kernel.org,
	Xiangwu Lai <laixiangwu@cmss.chinamobile.com>
X-Mailer: git-send-email 2.50.1.windows.1
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