🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #21333

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

#21333
From: Andrew Lunn
Date: Mon, 23 Nov 2026 21:40
106 lines
11523 bytes
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
Technical Details
Message-ID: <66d0cc53-b1e9-4c5d-adcd-ac752c21e3fe@lunn.ch>
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-369793-linux-kernel-netdev=dewy.ru
References: <179543215348.11880.18316180385674365789@mail.zgclab.edu.cn>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-369793-linux-kernel-netdev=dewy.ru
From: andrew@lunn.ch (Andrew Lunn)
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH v2] net: dsa: mt7530: disable the power rails on setup
 failure
Date: Mon, 23 Nov 2026 22:40:59 +0100
Organization: Usenet Network
Message-ID: <66d0cc53-b1e9-4c5d-adcd-ac752c21e3fe@lunn.ch>
References: <179543215348.11880.18316180385674365789@mail.zgclab.edu.cn>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: usenet.network;
	logging-data="3991347"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:XyBI5aGzgd6lZyaTOPLM+U+KiT8= sha256:PlG1OipyheHYBCbKZVbQkweQKQvyNN7IF68+PY26PTs=
	sha1:b+EaKjQx05dRFdvFWN6/mgcaVvY= sha256:QbB6kZ6ay8fI/fb40Iw1vQ2xKnsLuThfhQGpKTme8y4=
Content-Disposition: inline
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 4924D125DC7; Tue, 24 Nov 2026 00:41:53 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.05
X-Spam-Status: No, score=-3.05 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,
	DKIM_VALID_AU=-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=pass (1024-bit key)
	header.d=lunn.ch
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 S1XddU_4PYbP;
	Tue, 24 Nov 2026 00:41:48 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=104.64.211.4; helo=sin.lore.kernel.org; envelope-from=netdev+bounces-369793-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=lunn.ch
X-Received: from sin.lore.kernel.org (sin.lore.kernel.org [104.64.211.4])
	by mail.dewy.ru (Postfix) with ESMTPS id C5590125DB9; Tue, 24 Nov 2026 00:41:37 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sin.lore.kernel.org (Postfix) with ESMTP id AF5D625981; Mon, 23 Nov 2026 21:41:33 +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=1795470092;
	b=Dodfy+AC2FR5syaNZBI+SuibE+CgShXR81i5qRkkD5U1w4v9u2sOrAKBGgTFVYSGk91h
	 BKuyORwWKbW8imK7ZwNoWuxtVVGQY12/clO9UuwnxuVInh/QAUKaZZk0QMmPnZiYu2Pq1
	 bSVu0+wv3RRn2pSTufjXSPmxWjX6Z7E2r+YC4nC9kc/yRH049c3qbWiiApRl5rxqLy4Db
	 +B69o/AWUnF5cJDQ8k87culilP2j19lk960NVtrg584+yJCfqz3kNT7ZAuv32xC3C7M2O
	 eUZwRgDeZ0V/U9vItdtcapeb4Cl7k/4b4DNRJ46PYokqKiw6VVM79bZhmNv28TESCcQ==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795470092;
	h=X-Original-To:Received:DMARC-Filter:DKIM-Signature:Received:Date:
	 From:To:Cc:Subject:Message-ID:References:X-Mailing-List:List-Id:
	 List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner:
	 Precedence:MIME-Version:Content-Type:Content-Disposition:In-Reply-To;
	bh=GK26KF0rEouW6Pt03m3PN+6BNa6sEHxbDqdUEV8QxJ0=;
	b=xp1OTJFPv43RglYlAx+yvuKtgkM4pOLq/qknmvgAvFmel93KSPC+LJeywKFPG1MkxMIf
	 6BThpHuWu5IBP3RRiYQtzyaQQsCKF06ezaHST9dI/X2mvTngSKGfURa3AIRcQzJdIsogv
	 ywJ6uZIrNGyRY5lcLZ08V5gWjE2IVuukmu6+01ZhzKFBqzlo4tTWYQTrMp0zHvqRziKMV
	 6L4NSn88q/dFfLuqFZ687lanr29UYX0hc3d+DfPslLzOU37YHzx3uQV9PoYJmmXq7pnGH
	 sgweJMQonl3m2DJhIlfl8p/AkldKah464Z/BsgUcZ96wZIxhw1pX3UMbvwZ+mD/gRzA==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=lunn.ch header.i=@lunn.ch header.a=rsa-sha256 header.s=20171124 header.b=tFn3vYTn;
	dmarc=pass header.from=lunn.ch;
	spf=pass smtp.mailfrom=lunn.ch;
	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 D66C8606A333;
	Mon, 23 Nov 2026 21:41:32 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (1024-bit key) header.d=lunn.ch header.i=@lunn.ch header.a=rsa-sha256 header.s=20171124 header.b=tFn3vYTn
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=156.67.10.101
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1795470087;
	b=r1Wfz6MRpnzJm9M7gg2VY4aEYDO2HxfT2k0RydRtQgi8pURwT7p4S/NXBWTXr77rQZ7y
	 tW/7j/cz2vchVs50rDcjaL/1hrHHOjCRVMAvS5cjWK14cJ8n9RKEfNgCcOzx/+yqdkg7T
	 HSyckoiYRUz2qWm7czLCP4N2zaqVgHh3ET8+Yu8wlqTYw9vh2VrNVbaeBpMOB7JA11I55
	 mO9YuHyCXKX7SE3GgDavp1HSgye50gNH06yooLIm7ItUulgbuFXRbry95GAUVGws6J8mx
	 2WhVjaofexBi7zlWSNc2cN1Z5LhtwsGc0STfmoG6xNy2NM4R/dtBpsKh3u+YEXXeBxw==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795470087;
	h=DMARC-Filter:DKIM-Signature:Received:Date:From:To:Cc:Subject:
	 Message-ID:References:MIME-Version:Content-Type:Content-Disposition:
	 In-Reply-To;
	bh=GK26KF0rEouW6Pt03m3PN+6BNa6sEHxbDqdUEV8QxJ0=;
	b=gP3en73c8kAb61RfYwHvsQskreiVsVOQpg3fawZ8pMi/K3C4dhxlH7ofiHHy6L03hxZt
	 jdnDJ20X2WOAlAp+V+pYp0K/tl0iR+5aEQUz1aCKIK5l2d+0cw/UgTCxY9ThHUX3YoVDF
	 DONAWbsO9vFIm9wRiRW2WX5QQ4a+fi2SzE2pU3IsVoRI20d5CNculGEHAMn+8GwCQenbt
	 Fa0ZXms5Oxe7x/Zy3AHH8+Cl2A/yuxbDACf0y8ndotvItcMYXsXB9V4OGU1ACeAnLUpom
	 6KucpAAbbjeCT2jHCeAXSLupklOKJeAnCOQnMUrZaI/WjZOyrNuuWE+DcGM0n33sjug==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dmarc=pass header.from=lunn.ch;
	spf=pass smtp.mailfrom=lunn.ch;
	dkim=pass header.d=lunn.ch header.i=@lunn.ch header.a=rsa-sha256 header.s=20171124 header.b=tFn3vYTn;
	arc=none smtp.remote-ip=156.67.10.101
X-Received: from vps0.lunn.ch (vps0.lunn.ch [156.67.10.101])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange ECDHE (prime256v1) server-signature ECDSA (prime256v1) server-digest SHA256)
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id AA52E606A31E;
	Mon, 23 Nov 2026 21:41:26 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org AA52E606A31E
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=lunn.ch
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=lunn.ch
X-DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lunn.ch;
	s=20171124; h=In-Reply-To:Content-Disposition:Content-Type:MIME-Version:
	References:Message-ID:Subject:Cc:To:From:Date:From:Sender:Reply-To:Subject:
	Date:Message-ID:To:Cc:MIME-Version:Content-Type:Content-Transfer-Encoding:
	Content-ID:Content-Description:Content-Disposition:In-Reply-To:References;
	bh=GK26KF0rEouW6Pt03m3PN+6BNa6sEHxbDqdUEV8QxJ0=; b=tFn3vYTn+c1LCQlwETyuMJkJcF
	MZQjnZodQD4WfIFd0yqVj8/N/qmuABjfFQwg3DDOtNbMMIiypgKTo+4aHQfC9q8mivFou3pLxj/qa
	SpaTbQxa7z2H31vqQPvXTob93C/FuKwJD1eESkqbGZQfIAMyKlYuhd1fqHJ4ULSo48jI=;
X-Received: from andrew by vps0.lunn.ch with local (Exim 4.94.2)
	(envelope-from <andrew@lunn.ch>)
	id 1xVbmV-000u8B-8U; Mon, 23 Nov 2026 22:40:59 +0100
X-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
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
X-In-Reply-To: <179543215348.11880.18316180385674365789@mail.zgclab.edu.cn>