Article View: linux.kernel.netdev
Article #13122Re: [PATCH net-next] net: dsa: motorcomm: Free the MIB block on port teardown
From: netdev-bot+sashiko
Date: Mon, 09 Nov 2026 10:46
Date: Mon, 09 Nov 2026 10:46
145 lines
12545 bytes
12545 bytes
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.
Critical: 0 ยท High: 0 ยท 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).
- [Medium] The patch adds a memory leak on the yt921x_dsa_port_setup()
error path (drivers/net/dsa/motorcomm/chip.c).
- [Low] A comment in yt921x_phylink_mac_link_down()
(drivers/net/dsa/motorcomm/chip.c) is now false.
--
net: dsa: motorcomm: Free the MIB block on port teardown
The patch moves the per-port MIB block from devm_kzalloc() to
kvzalloc_obj() and frees it in yt921x_dsa_port_teardown(). The next
.setup() then gets zeroed counters after the hardware reset. The
disable/enable pairing of the MIB poll work in port_setup is dropped.
> diff --git a/drivers/net/dsa/motorcomm/chip.c b/drivers/net/dsa/motorcomm/chip.c
> index 33e5fc127244d..fd737c3e2e184 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);
> + }
> }
[Severity: Low]
This isn't a bug, but the MIB block is now freed here on every tree
teardown, so the comment in yt921x_phylink_mac_link_down() looks stale:
drivers/net/dsa/motorcomm/chip.c:yt921x_phylink_mac_link_down() {
...
/* No need to sync; port control block is hold until device remove */
pm = priv->ports[port].mib;
if (pm)
cancel_delayed_work(&pm->work);
...
}
The code still looks safe, but for a different reason. DSA stops and
destroys phylink before .port_teardown():
user ports: dsa_user_destroy()->dsa_port_phylink_destroy()
CPU/DSA ports: dsa_port_disable_rt()->phylink_stop(), then
dsa_shared_port_link_unregister_of()
All of these run before dsa_port_devlink_teardown().
Could this comment be updated to give that reason instead of the old
devm lifetime?
[ ... ]
> @@ -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;
> int res;
>
> if (!pm && (BIT(port) & yt921x_info_ports_mask(info))) {
> - pm = devm_kzalloc(dev, sizeof(*pm), GFP_KERNEL);
> + pm = kvzalloc_obj(*pm);
> if (!pm)
> return -ENOMEM;
> pp->mib = pm;
[ ... ]
> @@ -2031,9 +2026,6 @@ static int yt921x_dsa_port_setup(struct dsa_switch *ds, int port)
> if (res)
> return res;
[Severity: Medium]
Now that the MIB block is no longer devm-managed, does this error path
leak it?
pm is allocated with kvzalloc_obj() and stored in pp->mib before
yt921x_port_setup() runs. yt921x_port_setup() can fail, for example
when a register write fails in yt921x_userport_standalone() or in the
YT921X_PORTn_PRIO_ORD or YT921X_PORTn_ISOLATION writes. In that case
this function returns without freeing pm.
The DSA core doesn't call .port_teardown() after a failed .port_setup():
net/dsa/devlink.c:dsa_port_devlink_setup() {
...
err = ds->ops->port_setup(ds, dp->index);
if (err)
return err;
...
}
dp->setup stays false, so dsa_tree_teardown_ports()->dsa_port_teardown()
skips this port:
net/dsa/dsa.c:dsa_port_teardown() {
...
if (!dp->setup)
return;
...
}
yt921x_mdio_remove() frees the ACL blocks but not priv->ports[].mib.
With a single switch, dsa_register_switch() fails and so does probe.
The devm-allocated priv, which holds the only pointer to the block, is
then freed.
For user ports, dsa_port_setup_as_unused() retries and reuses the
leftover pm. If that retry also fails, the block leaks the same way.
The commit message says .port_teardown() "pairs with every successful
.port_setup()", which doesn't cover the failed-setup case.
Could this path kvfree(pm) and clear pp->mib when this call did the
allocation? Another option is to allocate only after yt921x_port_setup()
succeeds.
[ ... ]
--
Sashiko AI review ยท https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261108101648.1308271-1-mmyangfl%40gmail.com
Technical Details
Message-ID:
<179422120601.994134.564932634198490394@kernel.org>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-359215-linux-kernel-netdev=dewy.ruReferences:
<20261108101648.1308271-1-mmyangfl@gmail.com>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-359215-linux-kernel-netdev=dewy.ru From: netdev-bot+sashiko@kernel.org Newsgroups: linux.kernel.netdev Subject: Re: [PATCH net-next] net: dsa: motorcomm: Free the MIB block on port teardown Date: Mon, 09 Nov 2026 10:46:46 +0000 Organization: Usenet Network Message-ID: <179422120601.994134.564932634198490394@kernel.org> References: <20261108101648.1308271-1-mmyangfl@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="331756"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:X3b0+GOOWwUlfwtPTObGhk4mYqQ= sha256:GXq/ks+tQeaFfk+3p/0c/EmHFo8tHQHRu3vLjcB8oeA= sha1:hIi16ajungOaYORQt/sTQCIFibM= sha256:CnoRwqlB48NU1GtUt5MvAorTOY6rgPsISXZ09CZCtR8= 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 A5E57113794; Mon, 9 Nov 2026 13:47:54 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.401 X-Spam-Status: No, score=-3.401 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] 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 TewKIh9MPb-C; Mon, 9 Nov 2026 13:47:51 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-359215-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 9D89A113766; Mon, 9 Nov 2026 13:47:41 +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 1F1F4C5ED6; Mon, 9 Nov 2026 10:46:59 +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=1794221218; b=LmbN6uiBs7V+5sTdO6FHBawHM+iyzmOHL1dh8arZtupGhdcb6nSry2Dy66pZEHdG3vxV RPRhJDA+BTHgrmk+cU3rft1l3fUpeVniZbMBHa4YLocE+Nw1r4uiCfvdA/ryx0xZjF2nB QzvVSxXeL45Rlm86SVmBn0pzmQxjAk1x9GSxSielkJNhsTSLFBdPWqyKEY3QWbtBn3IbK hq4hZP+B6UJoV20z6drS2zDyclhq5eqyDXiYZf6WYIGxzEdHjfR0ZxXL9Cm2lEhh1eTqb w1BprJO/oUdOd4decY0jBjwD2vtMv43UJa8dFc1bGC5EjSfHB7kJASLQp/t0XyUbbmA== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794221218; 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=EGLRBtrqwLmpuLL/DC/Zcp+EGbQUnDJwdb8d7ZNXyZw=; b=rCNnvHn54wqcH20eHTLKaCb0OL4brbYSwra5IGd+Df+feeEsdYjhQtIM+L9kyzbPjeCo aPg6BNF6IMLFvYl8WxyjrTFSROr8GT4JMz7r+E/CsFrHpXl5Mqz28OidwGaaSbNWDMJLc XE8RgP/byywQ1fj9DFtNkytf9QnQ7RQfc1udNAAycFX/9LEfF3QgsLXLiocOL9kx9hF5N sdDBPn5HxqE/06kKDPyxhR2t2lMvn1ZkBoSYCz9hFBYiBINzd8oYZ0BJxGKD2Uc4mhcL3 gpUpfTmOc9CqWBBwj8c6SGNTuoKUD11tH5DWA3+7ZJZ6iDDvX6BkdjVVxEozW8JaH2w== 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="dro8/MQC"; 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 AA369606A335; Mon, 9 Nov 2026 10:46:58 +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=dro8/MQC 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=1794221207; b=z05KSNbMmbE2pxW83IbcBZjVVpDhroOXAk1PSTTyBhkSHEmkjczEuXx1oLNxG2XsKwaR hWGYAMgdfSH2tEmNlEcwo4phJOqF+Lwlg5iat21ycrVawpoVOiTzoj8Xz9ZAqve+YpywC R0S5zu2achbv3KruGnO+68FuDWMeRxX4FxnFxl5GXyetlpOQuZOeFfPtzMlLx7Ilk7KCb AJ44d9W1PK5NygrxyjfAA5zewDM11QrFV8if+kpZXu/mdgSAVKPAGSPq0s78eo8sbGdz8 6GlsjX1bIPZwmb825zifTnr5tZhu44f2KtxzHoNHeNxDqD2Y0SWBdE508vydEwbbffw== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794221207; 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=EGLRBtrqwLmpuLL/DC/Zcp+EGbQUnDJwdb8d7ZNXyZw=; b=lP9afI2B9UOe3FV8KnhMrzqO9dI8fDcp0JzNcml6xALAN3Kijg+3sm9lXRPQ1VMH5/mF ze2ez3TBSK9oHWWvYzn35MLId7pOM86XHKkMvy46HcW/25MUnV1yPIBb/5BTufXJP6+iV vrNKomeolnvlXk+1spxvQFrOxr5XOK1cSxoObf3HeBH/EP0TTVoZ1SvtGOgqFMGhxxAcQ L6pInn5jXRYXbF40JMEZ1j+D7LWMQ5/qxVGiIRkoEZxKtx7ktiD2iRUCMpV4A1vrARo1t +Fd+mEcZe+1z+fmHzqZX/+APVEemaNV1gjgF8ZJR8fjVA/eXyXOJ0Ynz3jlvDKEPXOw== 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="dro8/MQC"; 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 88486606A325; Mon, 9 Nov 2026 10:46:47 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 82E421F0089F; Mon, 9 Nov 2026 10:46:46 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1794221207; bh=EGLRBtrqwLmpuLL/DC/Zcp+EGbQUnDJwdb8d7ZNXyZw=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=dro8/MQCh7R7TbkAjW26BFB+ihtZj8Wbf7vP0yl/I+MaAhv/gOlpgbg3xqAvSJE0N TG0VHmR1JnLdYZWiTHIHdEkTKsnmJHiX6Yqg4KSUsNOt9MUW8sTW1XvYqXEPZSSsNA i/hgHWE5q3LZT3rcu1W3XHY5Ys5DoI+wOB93omFwluipdFFKoK8jUd61lz4I/ndNgo ieyq30nEKtMONxHi0pWIt03PAuKwhmwhAhSNlb3LyQMx4W7o3Aajq77qWQM+kVbzGz AhKNYYZhR0mpIwbyP1C0B8NVaEVlNXDm/OjXU8PdA5anFaVzN7p1W30A/TEuRu4Tvl HhiEw8uw4mNqQ== X-Cc: netdev@vger.kernel.org, andrew@lunn.ch, olteanv@gmail.com, davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com, linux-kernel@vger.kernel.org X-In-Reply-To: <20261108101648.1308271-1-mmyangfl@gmail.com> X-sashiko-severity: Medium 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