]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
net: rswitch: Avoid NULL pointer dereference during PHY access
authorMarek Vasut <marek.vasut+renesas@mailbox.org>
Wed, 25 Mar 2026 01:09:05 +0000 (02:09 +0100)
committerMarek Vasut <marek.vasut+renesas@mailbox.org>
Sat, 4 Apr 2026 21:46:31 +0000 (23:46 +0200)
At the very early stage when PHY ID is being auto-detected, the
PHY device is not yet instantiated and rswitch_etha .phydev is
still NULL. Add missing check for this condition and perform C22
fallback access in this PHY ID auto-detection case.

Signed-off-by: Marek Vasut <marek.vasut+renesas@mailbox.org>
drivers/net/rswitch.c

index 801c22bbdc7336bc4c83dfe846f4506c4c0b3b9d..c51908ed8f34b266af8ff6f78aa3652a85864166 100644 (file)
@@ -482,7 +482,7 @@ static int rswitch_mii_read_c45(struct mii_dev *miidev, int phyad, int devad, in
        /* Access PHY register */
        if (devad != MDIO_DEVAD_NONE)   /* Definitelly C45 */
                val = rswitch_mii_access_c45(etha_mii, true, phyad, devad, regad, 0);
-       else if (etha->phydev->is_c45)  /* C22 access to C45 PHY */
+       else if (etha->phydev && etha->phydev->is_c45)  /* C22 access to C45 PHY */
                val = rswitch_mii_access_c45(etha_mii, true, phyad, 1, regad, 0);
        else
                val = rswitch_mii_access_c22(etha_mii, true, phyad, regad, 0);
@@ -516,7 +516,7 @@ int rswitch_mii_write_c45(struct mii_dev *miidev, int phyad, int devad, int rega
        /* Access PHY register */
        if (devad != MDIO_DEVAD_NONE)   /* Definitelly C45 */
                rswitch_mii_access_c45(etha_mii, false, phyad, devad, regad, data);
-       else if (etha->phydev->is_c45)  /* C22 access to C45 PHY */
+       else if (etha->phydev && etha->phydev->is_c45)  /* C22 access to C45 PHY */
                rswitch_mii_access_c45(etha_mii, false, phyad, 1, regad, data);
        else
                rswitch_mii_access_c22(etha_mii, false, phyad, regad, data);