Article View: linux.kernel.netdev
Article #26223Re: [PATCH net-next v18 2/6] net: dsa: motorcomm: use max_ports in series for port bounds checking
From: netdev-bot+sashiko
Date: Thu, 03 Dec 2026 08:57
Date: Thu, 03 Dec 2026 08:57
114 lines
12412 bytes
12412 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] yt921x_mbus_int_init() in drivers/net/dsa/motorcomm/mdio_bus.c
leaks the mii_bus on the new max_ports error path.
- [Low] The commit message says the patch will "Validate max_ports
against the size of priv->ports (and the u32 width of phy_mask) before…
--
net: dsa: motorcomm: use max_ports in series for port bounds checking
This commit replaces the hardcoded YT921X_PORT_NUM with the per-series
max_ports field. The field is now used in the internal MDIO bus read and
write bounds checks and in the phy_mask setup in yt921x_mbus_int_init().
It also adds a validation of max_ports before it is used in GENMASK().
> Validate max_ports against the size of priv->ports (and the u32
> width of phy_mask) before using it in GENMASK().
[Severity: Low]
Does the code in yt921x_mbus_int_init() actually check the u32 width of
phy_mask? The only check is:
if (max_ports == 0 || max_ports > ARRAY_SIZE(priv->ports)) {
Nothing compares max_ports against 32 or BITS_PER_TYPE(u32). There is
also no static_assert() or BUILD_BUG_ON() that ties
ARRAY_SIZE(priv->ports) to the width of mbus->phy_mask.
The u32 bound only holds because struct yt921x_priv still declares:
struct yt921x_port ports[YT921X_PORT_NUM];
If priv->ports ever grew past 32 entries, GENMASK(max_ports - 1, 0) would
get an out-of-range shift that this check would not catch.
The commit message also says this "removes family-specific constants from
the common code path". The new bound is still YT921X_PORT_NUM through
ARRAY_SIZE(priv->ports), so a family with more than 11 ports would be
rejected rather than supported.
Could the message be reworded, or an explicit check be added for the u32
width?
> diff --git a/drivers/net/dsa/motorcomm/mdio_bus.c b/drivers/net/dsa/motorcomm/mdio_bus.c
> index a4062e6b0f000..a06e2cc94a3e2 100644
> --- a/drivers/net/dsa/motorcomm/mdio_bus.c
> +++ b/drivers/net/dsa/motorcomm/mdio_bus.c
[ ... ]
> @@ -155,6 +155,7 @@ int yt921x_mbus_int_init(struct yt921x_priv *priv, struct device_node *mnp)
> {
> struct device *dev = yt921x_priv_to_device(priv);
> struct mii_bus *mbus;
> + u32 max_ports;
> int res;
>
> mbus = mdiobus_alloc();
> @@ -167,7 +168,12 @@ int yt921x_mbus_int_init(struct yt921x_priv *priv, struct device_node *mnp)
> mbus->read = yt921x_mbus_int_read;
> mbus->write = yt921x_mbus_int_write;
> mbus->parent = dev;
> - mbus->phy_mask = (u32)~GENMASK(YT921X_PORT_NUM - 1, 0);
> + max_ports = priv->series->max_ports;
> + if (max_ports == 0 || max_ports > ARRAY_SIZE(priv->ports)) {
> + dev_err(dev, "Invalid max_ports: %u\n", max_ports);
> + return -EINVAL;
^^^^
[Severity: Medium]
Does this early return leak the mii_bus allocated by mdiobus_alloc() just
above?
mdiobus_alloc() is not devm-managed. priv->mbus_int is only set on
success, so the caller has no pointer it could free:
drivers/net/dsa/motorcomm/chip.c:yt921x_dsa_setup() {
...
res = yt921x_mbus_int_init(priv, child);
of_node_put(child);
if (res)
return res;
...
}
The of_mdiobus_register() failure path later in the same function does
call mdiobus_free(mbus) before returning.
The leak is also still there after the later patch in this series, "net:
dsa: motorcomm: use GENMASK_U32() for mbus phy_mask". That patch only
changes the phy_mask line.
Could the max_ports check be moved before mdiobus_alloc()? Alternatively,
mdiobus_free(mbus) could be called before returning -EINVAL.
> + }
> + mbus->phy_mask = (u32)~GENMASK(max_ports - 1, 0);
>
> res = of_mdiobus_register(mbus, mnp);
> if (res) {
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261202084022.3716891-1-kyle.switch%40motor-comm.com
Technical Details
Message-ID:
<179628824852.3146.765398832831553826@kernel.org>Path:
mbox-mo1.pugleaf.net!srv.newsdeef.eu.MISMATCH!feed-us-txt.newsdeef.eu!feed-us-ny.newsdeef.eu!srv.newsdeef.eu!feed-eu-txt.newsdeef.eu!feed-eu-ch.newsdeef.eu!srl.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-376414-linux-kernel-netdev=dewy.ruReferences:
<20261202084022.3716891-3-kyle.switch@motor-comm.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu.MISMATCH!feed-us-txt.newsdeef.eu!feed-us-ny.newsdeef.eu!srv.newsdeef.eu!feed-eu-txt.newsdeef.eu!feed-eu-ch.newsdeef.eu!srl.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-376414-linux-kernel-netdev=dewy.ru From: netdev-bot+sashiko@kernel.org Newsgroups: linux.kernel.netdev Subject: Re: [PATCH net-next v18 2/6] net: dsa: motorcomm: use max_ports in series for port bounds checking Date: Thu, 03 Dec 2026 08:57:28 +0000 Organization: Usenet Network Message-ID: <179628824852.3146.765398832831553826@kernel.org> References: <20261202084022.3716891-3-kyle.switch@motor-comm.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="2441464"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:FpDWyLLwL15OdqUTaaFhQ3vP3S8= sha256:W4hsM9DI5059gf23hpEfb62iRyOsHi9vZ0ctblC41Jc= sha1:9+dq7Xr2r8nqIeJvCH7smgZJUMg= sha256:YhHL5bntAewFrMeaqmyqKKU/Yck3NOfbv7iF4nCsV8M= 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 A123B117890; Thu, 3 Dec 2026 11:58:03 +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 5t-G8u7lerDZ; Thu, 3 Dec 2026 11:58:00 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-376414-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 E2E0811788D; Thu, 3 Dec 2026 11:57:51 +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 309B02DE3A; Thu, 3 Dec 2026 08:57:39 +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=1796288256; b=hI61/fA0WCZVqffamPhJac3G09W1MzjaK0KaSek+A5HjlzkakKhZqgLXpsyhtsUPO8Wi yP7zbRX6DADjfGsqS8f83M5w5gt+goYaB9icJrnFd2U2f3bRHwDtLErrV0PkWcHjtnSds FQ3/0puJWhMNfB9f/8XEHYTSLivPWGs5rQKp7WHSmai9T7q4Nq12uEKkKEdDYKJIJXlN4 hjqPnLBN4A4CxI7tC8BwV2fCYwvf9dI+W6yta68lwj9rw4BBzDgcbTcY5kamdaWe5Yrih 3OoM4YbumAqdjb4qRLkgxwEhCyELEjYMy3MPu7MHL4W6kHZplMzZG8z4MD4dwWnTBQA== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796288256; 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=YOAvfZVUIYNHZuvrMFUf/mRTcAfOIP3f2HB6WBjyr98=; b=JEgr1O6GT+mEQaO7DVh1SoWvkpBk2lzAk80HMPYQbOdl6eV5ON1t8qD7VILRrIzy4i9v koeADgXMHkP9fmyyLOmK4fEWiytknv9MP0wsTlyAhzwZUBqGpjuTld5WXRfVh0WtQE/7/ MA8y3z5DYZYG3ab17r09hnhSCeXN9803rs1m5ZOCDGYRL/z60NV3xH8UxZwBn0g1YwoMe geGXJnTWUb+/y7nWuvrDQT3bwAbpB8g2zeKIxaGn5TyXgnEkPOnQ+r7k2F+iA7iafKzwW HYsjIwlKE4Q8UUDNPbAUL+AfQI27/dywygSZ6KPOPQbzMbQX5IWMe2AcS6vuvMv3ikQ== 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=Lzxq8Q2V; 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 96BA6606A333; Thu, 3 Dec 2026 08:57:36 +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=Lzxq8Q2V 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=1796288250; b=laok2BjagDqbs07g++Tu3HD5h9QhagDYg5507HUZDghDnYWQbKehv/BGrvZTH8SenK70 2p2fK5CdqbFXxGDdU4dsNfbG1CdjRcve/qCbltn2qcspbT/DjTTwz7ApDsnydxuc72p5O zVxWDCPVBOR2QDqJWqjAtk5uYWG0+g2u+zYNvQ2ir1X+zgaNXxF6kpRNiHvdGuZJ71ev9 wS8x7kFzXX+K9nv6hngxOwaHjWXYBDodSgqR90VSweU8dmJWtLALGJMcAKHKqustcW6WK CcYeTGJZVL8sdQpzG1/D0Dq1qzXUwf+GcpeK0RCAQZATp743t8WXn0uX+674dGcCcCg== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796288250; 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=YOAvfZVUIYNHZuvrMFUf/mRTcAfOIP3f2HB6WBjyr98=; b=QF0lf4SfMqrhZxwyZCKdAOZzoSZjgZs/YPbpSrkWP/kfiTaofJ19JWWCIsWvEjmAcbeJ QM6KO9r5yP7FnSI4HCPtAIPAddOLZqWiTHdA6Mas5p/yW5KeCH1sFH3Pu5MERpNB/eUpi 4H/m9rM/Eu/9Smyknp9zTHfAyBSwgaGgv3QhQGrtRsaDs+X50nulDcLAcx7KZTYNvy+Ch 1z/MvMOK6zwUhyMTB4jhlGayfokR7OupqXDrdEa3C2OZo86/eE0y43h84dQnoRepQOm5B 9Clcm3rv+wfYcWVxXB5Q/vBvYHMWR3foo4ZcZMraNiOtDRgdbfinlK9GNDiUnj1mRJA== 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=Lzxq8Q2V; 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 B719F606A32C; Thu, 3 Dec 2026 08:57:30 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 046431F000C1; Thu, 3 Dec 2026 08:57:28 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796288250; bh=YOAvfZVUIYNHZuvrMFUf/mRTcAfOIP3f2HB6WBjyr98=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=Lzxq8Q2VO+vSa4MZM4w2MHnVBgoRxAQ+ggYyfvXD6Izn4up1WVjbPe5ICW5e+GXkl FBLD8/2FFjc7N6bsm4yKYTqL9qX4k8l4YNHVpHcTc74hA3fQ4ttzWWVQYluzHIpGSD VzTcVeg+UR33UfjrD9GCuqsKa8jPXtWpB7BpWXQuJBMsB/W1vraGz6fVNtcAwJDw76 pOltoBTN+xoGAS5jvL3wshhDjwFtsBH1sVes7gsSoSjCjs6E616y+j4QRIgmWBWEpi Tq0YD6bRM/kh8KSxR2vXBCrHKKa4c3fzGVZiMzFnCgxXZJdXGJY3F2A8YTZV61fCdF jtaOvtjxhKCXw== X-Cc: andrew@lunn.ch, olteanv@gmail.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, mmyangfl@gmail.com, horms@kernel.org, linux@armlinux.org.uk, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org, david.laight.linux@gmail.com, ming.xu@motor-comm.com, xiaolin.xu@motor-comm.com, jianmin.wang@motor-comm.com, wei.zhang@gl-inet.com, sijia.huang@gl-inet.com X-In-Reply-To: <20261202084022.3716891-3-kyle.switch@motor-comm.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