[PATCH net-next v11 2/7] net: dsa: motorcomm: use max_ports in series for port bounds checking

From: Kyle Switch

Date: Fri Oct 02 2026 - 13:37:44 EST


Replace the hardcoded YT921X_PORT_NUM macro with the per-series
max_ports field in port validation. This removes family-specific
constants from the common code path and simplifies adding new
switch families with different port counts.

No functional change for existing YT921X devices.

Reviewed-by: Andrew Lunn <andrew@xxxxxxx>
Signed-off-by: Kyle Switch <kyle.switch@xxxxxxxxxxxxxx>
---
drivers/net/dsa/motorcomm/mdio_bus.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/net/dsa/motorcomm/mdio_bus.c b/drivers/net/dsa/motorcomm/mdio_bus.c
index 1a3f3cc68275..c5a0f1bc1e36 100644
--- a/drivers/net/dsa/motorcomm/mdio_bus.c
+++ b/drivers/net/dsa/motorcomm/mdio_bus.c
@@ -115,7 +115,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);
@@ -133,7 +133,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);
@@ -147,6 +147,7 @@ int yt921x_mbus_int_init(struct yt921x_priv *priv, struct device_node *mnp)
{
struct device *dev = to_device(priv);
struct mii_bus *mbus;
+ u32 max_ports;
int res;

mbus = devm_mdiobus_alloc(dev);
@@ -159,7 +160,8 @@ 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;
+ mbus->phy_mask = (u32)~GENMASK(max_ports - 1, 0);

res = devm_of_mdiobus_register(dev, mbus, mnp);
if (res)
--
2.25.1