[PATCH] net: rswitch: Avoid NULL pointer dereference during PHY access
Marek Vasut
marek.vasut+renesas at mailbox.org
Wed Mar 25 02:09:05 CET 2026
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 at mailbox.org>
---
Cc: Andrew Goodbody <andrew.goodbody at linaro.org>
Cc: Hai Pham <hai.pham.ud at renesas.com>
Cc: Jerome Forissier <jerome.forissier at arm.com>
Cc: Nobuhiro Iwamatsu <iwamatsu at nigauri.org>
Cc: Phong Hoang <phong.hoang.wz at renesas.com>
Cc: Tam Nguyen <tam.nguyen.xa at renesas.com>
Cc: Thanh Quan <thanh.quan.xn at renesas.com>
Cc: Tom Rini <trini at konsulko.com>
Cc: u-boot at lists.denx.de
---
drivers/net/rswitch.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/net/rswitch.c b/drivers/net/rswitch.c
index 801c22bbdc7..c51908ed8f3 100644
--- a/drivers/net/rswitch.c
+++ b/drivers/net/rswitch.c
@@ -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);
--
2.53.0
More information about the U-Boot
mailing list