🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #13252

[PATCH net-next v2] net: dsa: motorcomm: Free the MIB block on port teardown

#13252
From: David Yang
Date: Mon, 09 Nov 2026 14:46
86 lines
13468 bytes
.setup() can run again within one registration: removing another switch
from the tree tears the whole tree down, and re-probing sets every
member switch up again.

The hardware reset at the start of .setup() brings the MIB counters back
to zero, but a MIB block kept across that cycle still holds the old
software buffer, so the next yt921x_mib_read() treats the small value as
a 32-bit wrap and adds 2^32 to every counter it extends.

The old claim, get_stats64() not being synchronized with
.port_teardown(), is not true, thus free the MIB block in
.port_teardown(), so the next setup allocates zeroed blocks.

Not carrying a fix tag since there are no known multi-chip yt921x users.

Signed-off-by: David Yang <mmyangfl@gmail.com>
---
v2:
 - free the block on the error path
v1: https://lore.kernel.org/r/20261108101648.1308271-1-mmyangfl@gmail.com
 drivers/net/dsa/motorcomm/chip.c | 26 ++++++++++----------------
 1 file changed, 10 insertions(+), 16 deletions(-)

diff --git a/drivers/net/dsa/motorcomm/chip.c b/drivers/net/dsa/motorcomm/chip.c
index 33e5fc127244..7e86d992bd97 100644
--- a/drivers/net/dsa/motorcomm/chip.c
+++ b/drivers/net/dsa/motorcomm/chip.c
@@ -1994,11 +1994,11 @@ static void yt921x_dsa_port_teardown(struct dsa_switch *ds, int port)
 	struct yt921x_port *pp = &priv->ports[port];
 	struct yt921x_mib *pm = pp->mib;
 
-	/* get_stats64() might not be synchronized with port_teardown(), hold
-	 * the MIB block till the device teardown
-	 */
-	if (pm)
+	if (pm) {
 		disable_delayed_work_sync(&pm->work);
+		pp->mib = NULL;
+		kvfree(pm);
+	}
 }
 
 static int yt921x_dsa_port_setup(struct dsa_switch *ds, int port)
@@ -2006,12 +2006,11 @@ static int yt921x_dsa_port_setup(struct dsa_switch *ds, int port)
 	struct yt921x_priv *priv = dsa_to_yt921x_priv(ds);
 	struct yt921x_port *pp = &priv->ports[port];
 	const struct yt921x_info *info = priv->info;
-	struct device *dev = yt921x_priv_to_device(priv);
-	struct yt921x_mib *pm = pp->mib;
+	struct yt921x_mib *pm;
 	int res;
 
-	if (!pm && (BIT(port) & yt921x_info_ports_mask(info))) {
-		pm = devm_kzalloc(dev, sizeof(*pm), GFP_KERNEL);
+	if (BIT(port) & yt921x_info_ports_mask(info)) {
+		pm = kvzalloc_obj(*pm);
 		if (!pm)
 			return -ENOMEM;
 		pp->mib = pm;
@@ -2019,20 +2018,15 @@ static int yt921x_dsa_port_setup(struct dsa_switch *ds, int port)
 		pm->port = pp;
 		u64_stats_init(&pm->syncp);
 		INIT_DELAYED_WORK(&pm->work, yt921x_mib_poll);
-		/* Start disabled, so that the enable below always pairs with
-		 * either this disable or the one from a previous teardown
-		 */
-		disable_delayed_work_sync(&pm->work);
 	}
 
 	mutex_lock(&priv->reg_lock);
 	res = yt921x_port_setup(priv, port);
 	mutex_unlock(&priv->reg_lock);
-	if (res)
+	if (res) {
+		yt921x_dsa_port_teardown(ds, port);
 		return res;
-
-	if (pm)
-		enable_delayed_work(&pm->work);
+	}
 
 	return 0;
 }
-- 
2.53.0
Technical Details
Message-ID: <20261109144705.1737460-1-mmyangfl@gmail.com>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-359372-linux-kernel-netdev=dewy.ru

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-359372-linux-kernel-netdev=dewy.ru
From: mmyangfl@gmail.com (David Yang)
Newsgroups: linux.kernel.netdev
Subject: [PATCH net-next v2] net: dsa: motorcomm: Free the MIB block on port teardown
Date: Mon,  9 Nov 2026 22:46:50 +0800
Organization: Usenet Network
Message-ID: <20261109144705.1737460-1-mmyangfl@gmail.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="381070"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:ngWg6lGlhnXEn1ZuXbVhNCaCZpw= sha256:/hixM85ACuO93fOy6AbZYHR5/LeRsQK/rOl0rl/74nw=
	sha1:CQkJjh4oEvDbG/fiej9W/HTJXwI= sha256:Gu6/vipvflkwjIORxB5mvbcVWhj+MWEnWzE4BmRHHhA=
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 3CE07113839; Mon,  9 Nov 2026 17:51:40 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.049
X-Spam-Status: No, score=-3.049 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, FREEMAIL_FORGED_FROMDOMAIN=0.001,
	FREEMAIL_FROM=0.001, 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] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=gmail.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 L0_nQgl7ax_q;
	Mon,  9 Nov 2026 17:51:36 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-359372-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=gmail.com
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id EEA18113837; Mon,  9 Nov 2026 17:51:27 +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 676F9E42F7; Mon,  9 Nov 2026 14:47:46 +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=1794235664;
	b=QnL3nsW35edRHt24V5hpJYovZHiiFa1FR1W+1rjkUcMsLnIBSpao98NbnFA5fYZG1UIq
	 G9/9/vBDMdYfhlBXu+HKvCVlfzwGm2j8GT+KQC1qiiKlEV12nzDJJ84etpkMZstejUpqU
	 iTotHfWu2xp1PHP5M7x+vYJi0SXdsieisPGGVBzvAEHKAZOBd3MaIHf+ERW622oVGPcrF
	 efQak01t+9BxGAAd1G8fd+EhBDONcsiWKuyNdxGkMOqalccdrIGLTTXFYlKu6SnvhhIA6
	 so5mQbnElNfCvKsYru2x4Q8iG4dAtCOVCttSeQ+Wq7SKf//fn3xX7oKBkBC7mK8YL7g==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794235664;
	h=X-Original-To:Received:DMARC-Filter:Received:DKIM-Signature:
	 X-Google-DKIM-Signature:X-Gm-Message-State:X-Gm-Gg:X-Received:
	 Received: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=8BjfBvvBITs0v8vpJBTpPDcN60M30b+tl6LUSDLYEFY=;
	b=lwPV80qqi68Nc7y3anNBv2Pyd4F9zLn7x3nzkQFDluaustgnbANb0dga6wS6qOgQt7R5
	 90bGhxQffb56HlTduR9PI21GmVua+TCoMVloEHbfriXVlbzL1vogVHtfN/PH9Kwx3zpMw
	 5LysI7gH1xS3mFLnrXDfuMFN9D1AfJqcZRwGhC+I7v87KnLDIGFrIeu+yXGGV6vIBtnBZ
	 ajs/2T8wXRhEup2ILvFNMqRkDU4P/CmP6fyRK0/q8LkDB3a5C/DbBhjjMgtPRXcSc711+
	 q7Dh+CNvhXMLFHK8TmRjxTK7Cp3gQL9luxbrvD+OUXrzESyN5CqQLNj2KJW617iN/FA==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=T+qVH9bO;
	dmarc=pass header.from=gmail.com;
	spf=pass smtp.mailfrom=gmail.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 CF63F606D806;
	Mon,  9 Nov 2026 14:47:44 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=T+qVH9bO
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.214.182
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1794235664;
	b=l6LGpTBcql1Y8j7QBj3Ijg7O9QlqB9QFW9cAktLgdeom4eg94OK8hqW7f1VCeI327YJo
	 kgrVth2JMa+0X6Jz2t7S9817CtIQDt/QLfq/8gcncNKx/9TKvhWTztvpKsnjaUPs/9y/h
	 QbQrNj409HHxTrOVcVAEFeTcWHW3BUX/rz1zfKIKu5n4nckWVHcE5Y8gctBJH80CaGDoP
	 TB1XVgzVUctvebI2dTfF0B8H27fkf+hKNq61v5Fc8E+HbwXsa7wrAqeUmzUx3rMFeGP9q
	 k9bNnZpIFgL1cbMu3bkIxRVglBolGri60vFNU8JF7yMnimvlo3nuqrcQT1W0xXW+j8g==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794235664;
	h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature:
	 X-Gm-Message-State:X-Gm-Gg:X-Received:Received:From:To:Cc:Subject:
	 Date:Message-ID:X-Mailer:MIME-Version:Content-Transfer-Encoding;
	bh=8BjfBvvBITs0v8vpJBTpPDcN60M30b+tl6LUSDLYEFY=;
	b=sqmb+obuOxe3E4lc9JQROjIvmWkGI/xTvFpXIclgVch06+/BaeOmkeHDcg/VmItPkFhc
	 yiZgss6vWM4efczYFhE+A2POxJIKMTCmfD75tJfvIqBv97r8yqkAm5JKDH91mNk6VLK/w
	 T/nRF857Qi+zSQAxcD2G4a1fuzREI/4gntifyepCoA3oBFduKTaPmC9447150+ufvbDik
	 aNHUV4cqKk9+uVpgZLHC5NwzLF3zBxWTlkNynqEEN91pMPOLSSR0yL/7NlVQBiGb0q2Fm
	 igSrp7eSyHUP0QeNksabW7/0SqysfvjiQcyBcmhGrtGapWySMEIJLEUf/0d9ejwrjlw==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dmarc=pass header.from=gmail.com;
	spf=pass smtp.mailfrom=gmail.com;
	dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=T+qVH9bO;
	arc=none smtp.remote-ip=209.85.214.182
X-Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182])
	(using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256)
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id A46ED606D803
	for <netdev@vger.kernel.org>; Mon,  9 Nov 2026 14:47:43 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org A46ED606D803
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com
X-Received: by mail-pl1-f182.google.com with SMTP id d9443c01a7336-2eb0f1b592bso3328335ad.1
        for <netdev@vger.kernel.org>; Mon, 09 Nov 2026 06:47:43 -0800 (PST)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20260707; t=1794235663; x=1794840463; darn=vger.kernel.org;
        h=content-transfer-encoding:mime-version:message-id:date:subject:cc
         :to:from:from:to:cc:subject:date:message-id:reply-to:content-type;
        bh=8BjfBvvBITs0v8vpJBTpPDcN60M30b+tl6LUSDLYEFY=;
        b=T+qVH9bOyUcTzDcway48pCmwpWUfpZPavCJZ3yrePOD9wIRZIigPmfpFCW6z28tvaf
         AvJJ6NX2oIL63z3W44FqeXoXezQGEsCiYenen7cqF+AZLFG2RS/Bq8UObNwHpAdVb0km
         UWaAeQLkp/UV7WpqEfZnfA+f6gFqaQUINiukPpViF19AzGaxLImRVe7xaNz6vhsBR9XK
         JCwOibXmHp1pXFwMRlgqP3muI/gw4IBfB9uvzhAAGbFyiPTMdNaBPN+yD+P+nnRPk6yu
         Dcql4IZCCcAVAPjK82ltbtjYv2pccTsglh+ykwgBVlfE7Aouz7gdGwGXLJk0LYiqz0cI
         mtyg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20260707; t=1794235663; x=1794840463;
        h=content-transfer-encoding:mime-version:message-id:date:subject:cc
         :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date
         :message-id:reply-to:content-type;
        bh=8BjfBvvBITs0v8vpJBTpPDcN60M30b+tl6LUSDLYEFY=;
        b=HfL6HNgTTL1NOTDPxFXVJS0Rt3gjUND3IxNMB5f2PFpjH/2vlWaf9+BLE6v6SQVDVy
         vYVyjo7PxA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Wb4AXeIPgLVvjA8xl5kcFNKGKr2AA==
X-Received: by 2002:a17:902:e80a:b0:2e9:a090:dd69 with SMTP id d9443c01a7336-2ed83777169mr42173915ad.39.1794235662770;
        Mon, 09 Nov 2026 06:47:42 -0800 (PST)
X-Received: from d.home.yangfl.dn42 ([2a09:bac1:76a0:28::1d2:30])
        by smtp.gmail.com with ESMTPSA id d9443c01a7336-2ed8146de34sm12511945ad.5.2026.11.09.06.47.39
        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
        Mon, 09 Nov 2026 06:47:42 -0800 (PST)
X-Cc: David Yang <mmyangfl@gmail.com>,
	Andrew Lunn <andrew@lunn.ch>,
	Vladimir Oltean <olteanv@gmail.com>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@kernel.org>,
	Jakub Kicinski <kuba@kernel.org>,
	Paolo Abeni <pabeni@redhat.com>,
	linux-kernel@vger.kernel.org
X-Mailer: git-send-email 2.53.0
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