]> git.ipfire.org Git - thirdparty/openwrt.git/commitdiff
realtek: mdio: harden rtmdio_get_phy_info()
authorMarkus Stockhausen <markus.stockhausen@gmx.de>
Wed, 6 May 2026 14:25:05 +0000 (16:25 +0200)
committerRobert Marko <robimarko@gmail.com>
Mon, 11 May 2026 08:32:29 +0000 (10:32 +0200)
Improve error checking and code flow.

Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
Link: https://github.com/openwrt/openwrt/pull/23230
Signed-off-by: Robert Marko <robimarko@gmail.com>
target/linux/realtek/files-6.18/drivers/net/mdio/mdio-realtek-otto.c

index 33aa540146a90fb92aa82b679d0694a761f714b3..b7623628fa158fd21dea1e8b870b9e485b48c2e9 100644 (file)
@@ -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)