Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

net: stmmac: mdio: fix incorrect phy address check

max_addr is the max number of addresses, not the highest possible address,
therefore check phydev->mdio.addr > max_addr isn't correct.
To fix this change the semantics of max_addr, so that it represents
the highest possible address. IMO this is also a little bit more intuitive
wrt name max_addr.

Fixes: 4a107a0e8361 ("net: stmmac: mdio: use phy_find_first to simplify stmmac_mdio_register")
Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
Reported-by: Simon Horman <horms@kernel.org>
Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
Reviewed-by: Simon Horman <horms@kernel.org>
Link: https://patch.msgid.link/e869999b-2d4b-4dc1-9890-c2d3d1e8d0f8@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Heiner Kallweit and committed by
Jakub Kicinski
cf35f434 10c7b9be

+2 -7
+2 -7
drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
··· 583 583 struct device_node *mdio_node = priv->plat->mdio_node; 584 584 struct device *dev = ndev->dev.parent; 585 585 struct fwnode_handle *fixed_node; 586 + int max_addr = PHY_MAX_ADDR - 1; 586 587 struct fwnode_handle *fwnode; 587 588 struct phy_device *phydev; 588 - int max_addr; 589 589 590 590 if (!mdio_bus_data) 591 591 return 0; ··· 609 609 610 610 if (priv->synopsys_id < DWXGMAC_CORE_2_20) { 611 611 /* Right now only C22 phys are supported */ 612 - max_addr = MII_XGMAC_MAX_C22ADDR + 1; 612 + max_addr = MII_XGMAC_MAX_C22ADDR; 613 613 614 614 /* Check if DT specified an unsupported phy addr */ 615 615 if (priv->plat->phy_addr > MII_XGMAC_MAX_C22ADDR) 616 616 dev_err(dev, "Unsupported phy_addr (max=%d)\n", 617 617 MII_XGMAC_MAX_C22ADDR); 618 - } else { 619 - /* XGMAC version 2.20 onwards support 32 phy addr */ 620 - max_addr = PHY_MAX_ADDR; 621 618 } 622 619 } else { 623 620 new_bus->read = &stmmac_mdio_read_c22; ··· 623 626 new_bus->read_c45 = &stmmac_mdio_read_c45; 624 627 new_bus->write_c45 = &stmmac_mdio_write_c45; 625 628 } 626 - 627 - max_addr = PHY_MAX_ADDR; 628 629 } 629 630 630 631 if (mdio_bus_data->needs_reset)