From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=115.124.28.124 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796200840; b=pLwmjU1+fLq5FmAmuDUeIJOO9mH2OCKEXWAvqGUfo7DZqWu0JQErV4ZtJFuhsyvKLZoP hxrtU3Aj2ecPQCkasGzcTbiEkpqnkcE65liyAMLBMbwMtPQgUBSlQZBumWzj+XcX4jBB0 xbI9zQBzAg6t+K2+E3zyHGMlae64m496qKEEB8a+lGaANlvX9Gu22p4Y5oKnw7Uwohl9q z9HEM06WH3pVwEUWWTnv15UjCG3pgocrHoemrlnkSqe1g0qNbtrY0pIZ2oE0oD9WVh7/0 wQlrRQTMoGPwe5dxdFsaemy8pIuLXWDZJV6TPCpJ0OVYZGZU/BlXHGs/kvX9lfrBTYg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796200840; h=DMARC-Filter:X-Alimail-AntiSpam:Received:From:To:Cc:Subject:Date: Message-Id:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; bh=5a4gdUvZygk7wMpHqYWpzsvPksEktnfBv6SgSna7FJI=; b=RLS6ofO8vw/hz4GZej1RP6bHqHqbXQesW6mxqbuSXpL5bzxHm0GNgK+mLTF86m1q2EMk 3zGmqwoi2JhApPbZfqXy1BIGsaslo9IFrREVIxIfXXOsrYV/vY4a59r3cO5bwns/J4AO0 SO7qrbMGTajWBR9VCNSrZMSa7wbrXo1qsoqrRFUr9tzIMxlg57PQaX02WwLpbGf4ElXu8 N3q+VbUhW/vM9+ASONSgSgrkBbniuZYEau/6DvWlB+k1nQleeSbsbACLnZX7qmI44Xwa2 M85YvHDK+2yaEa0yg3tJkeYc5wlwRIrsrByGVcgTP0EXGbvHb6aPki/WMDKDjwriSpQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=motor-comm.com; spf=pass smtp.mailfrom=motor-comm.com; arc=none smtp.remote-ip=115.124.28.124 Received: from out28-124.mail.aliyun.com (out28-124.mail.aliyun.com [115.124.28.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5E101606A6B0; Wed, 2 Dec 2026 08:40:39 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 5E101606A6B0 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=motor-comm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=motor-comm.com X-Alimail-AntiSpam:AC=CONTINUE;BC=0.07572671|-1;CH=green;DM=|CONTINUE|false|;DS=CONTINUE|ham_system_inform|0.00780706-0.00041437-0.991779;FP=11707007026674192018|0|0|0|0|-1|-1|-1;HT=maildocker-contentspam033037028158;MF=kyle.switch@motor-comm.com;NM=1;PH=DS;RN=20;RT=20;SR=0;TI=SMTPD_---.kEtRdhO_1796200829; Received: from motor-comm.com(mailfrom:kyle.switch@motor-comm.com fp:SMTPD_---.kEtRdhO_1796200829 cluster:ay29) by smtp.aliyun-inc.com; Wed, 02 Dec 2026 16:40:30 +0800 From: Kyle Switch To: 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 Cc: 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 Subject: [PATCH net-next v18 2/6] net: dsa: motorcomm: use max_ports in series for port bounds checking Date: Wed, 2 Dec 2026 16:40:18 +0800 Message-Id: <20261202084022.3716891-3-kyle.switch@motor-comm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20261202084022.3716891-1-kyle.switch@motor-comm.com> References: <20261202084022.3716891-1-kyle.switch@motor-comm.com> X-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Replace the hardcoded YT921X_PORT_NUM macro with the per-series max_ports field in port validation and in the internal mii_bus phy_mask setup. This removes family-specific constants from the common code path and simplifies adding new switch families with different port counts. Validate max_ports against the size of priv->ports (and the u32 width of phy_mask) before using it in GENMASK(). No functional change for existing YT921X devices, as their max_ports equals YT921X_PORT_NUM. Reviewed-by: Andrew Lunn Signed-off-by: Kyle Switch --- drivers/net/dsa/motorcomm/mdio_bus.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/drivers/net/dsa/motorcomm/mdio_bus.c b/drivers/net/dsa/motorcomm/mdio_bus.c index a4062e6b0f00..a06e2cc94a3e 100644 --- a/drivers/net/dsa/motorcomm/mdio_bus.c +++ b/drivers/net/dsa/motorcomm/mdio_bus.c @@ -113,7 +113,7 @@ static int yt921x_mbus_int_read(struct mii_bus *mbus, int port, int reg) u16 val; int res; - if (port >= YT921X_PORT_NUM) + if (port >= priv->series->max_ports) return U16_MAX; mutex_lock(&priv->reg_lock); @@ -131,7 +131,7 @@ yt921x_mbus_int_write(struct mii_bus *mbus, int port, int reg, u16 data) struct yt921x_priv *priv = mbus->priv; int res; - if (port >= YT921X_PORT_NUM) + if (port >= priv->series->max_ports) return -ENODEV; mutex_lock(&priv->reg_lock); @@ -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; + } + mbus->phy_mask = (u32)~GENMASK(max_ports - 1, 0); res = of_mdiobus_register(mbus, mnp); if (res) { -- 2.25.1