From: David Yang <mmyangfl@gmail.com>
To: netdev@vger.kernel.org
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
Subject: [PATCH net-next v2] net: dsa: motorcomm: Free the MIB block on port teardown
Date: Mon, 9 Nov 2026 22:46:50 +0800 [thread overview]
Message-ID: <20261109144705.1737460-1-mmyangfl@gmail.com> (raw)
.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
next reply other threads:[~2026-11-09 14:47 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-09 14:46 David Yang [this message]
2026-11-09 14:51 ` netdev-bot+sinfo
2026-11-09 14:52 ` David Yang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261109144705.1737460-1-mmyangfl@gmail.com \
--to=mmyangfl@gmail.com \
--cc=andrew@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=olteanv@gmail.com \
--cc=pabeni@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®