From: Markus Stockhausen Date: Wed, 6 May 2026 14:25:05 +0000 (+0200) Subject: realtek: mdio: harden rtmdio_get_phy_info() X-Git-Url: http://git.ipfire.org/gitweb/index.cgi?a=commitdiff_plain;h=8cf43d8b667fc5f8b23e27c33c30ee8c19fd7345;p=thirdparty%2Fopenwrt.git realtek: mdio: harden rtmdio_get_phy_info() Improve error checking and code flow. Signed-off-by: Markus Stockhausen Link: https://github.com/openwrt/openwrt/pull/23230 Signed-off-by: Robert Marko --- diff --git a/target/linux/realtek/files-6.18/drivers/net/mdio/mdio-realtek-otto.c b/target/linux/realtek/files-6.18/drivers/net/mdio/mdio-realtek-otto.c index 33aa540146a..b7623628fa1 100644 --- a/target/linux/realtek/files-6.18/drivers/net/mdio/mdio-realtek-otto.c +++ b/target/linux/realtek/files-6.18/drivers/net/mdio/mdio-realtek-otto.c @@ -684,19 +684,18 @@ static u32 rtmdio_get_phy_id(struct phy_device *phydev) static int rtmdio_get_phy_info(struct rtmdio_ctrl *ctrl, int pn, struct rtmdio_phy_info *phyinfo) { - struct mii_bus *bus = ctrl->bus[ctrl->port[pn].smi_bus].mii_bus; - int addr = ctrl->port[pn].smi_addr; - int ret = 0; - u32 phyid; + struct mii_bus *bus; + u32 smi_addr, phyid; - /* - * Depending on the attached PHY the polling mechanism must be fine tuned. Basically - * this boils down to which registers must be read and if there are any special - * features. - */ - memset(phyinfo, 0, sizeof(*phyinfo)); - phyid = rtmdio_get_phy_id(mdiobus_get_phy(bus, addr)); + if (!test_bit(pn, ctrl->valid_ports)) + return -EINVAL; + + bus = ctrl->bus[ctrl->port[pn].smi_bus].mii_bus; + smi_addr = ctrl->port[pn].smi_addr; + phyid = rtmdio_get_phy_id(mdiobus_get_phy(bus, smi_addr)); + /* Determine PHY specific characteristics for polling fine tuning */ + memset(phyinfo, 0, sizeof(*phyinfo)); switch (phyid) { case RTMDIO_PHY_AQR113C_A: case RTMDIO_PHY_AQR113C_B: @@ -728,11 +727,10 @@ static int rtmdio_get_phy_info(struct rtmdio_ctrl *ctrl, int pn, struct rtmdio_p break; default: dev_warn(&bus->dev, "skip polling setup for phy 0x%08x on port %d\n", phyid, pn); - ret = -EINVAL; - break; + return -EINVAL; } - return ret; + return 0; } static int rtmdio_838x_setup_ctrl(struct rtmdio_ctrl *ctrl)