Skip to contentSkip to conversation

net: mvpp2: fix NULL pointer dereference in mvpp2_phy_connect

PATCH In review Vincent Jardin 2 participants 2 messages Dec 16, 2025 – Jun 10 Network drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: mvpp2: fix NULL pointer dereference in mvpp2_phy_connect

Fix two NULL pointer dereferences in mvpp2_phy_connect():

1. port->phy_dev->dev is used in dev_warn() but port->phy_dev is not assigned yet (assigned later at line below).

2. port->phy_dev->dev is used in dev_err() inside the "if (!phy_dev)" block, which means phy_dev is NULL.

Both cases would cause a crash if the PHY detection fails or returns a generic PHY. Use the already available 'dev' parameter instead.

Fixes 9db60ee470c2 ("net: mvpp2: Convert netdev_xxx to dev_xxx")
---
 drivers/net/mvpp2.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/mvpp2.c +2 -2
index ae545fe229c..3f6f1978f2f 100644
@@ -4530,7 +4530,7 @@ static void mvpp2_phy_connect(struct udevice *dev, struct mvpp2_port *port)
 		 */
 		if (phy_dev &&
 		    phy_dev->drv->uid == 0xffffffff) {/* Generic phy */
-			dev_warn(port->phy_dev->dev,
+			dev_warn(dev,
 				 "Marking phy as invalid, link will not be checked\n");
 			/* set phy_addr to invalid value */
 			port->phyaddr = PHY_MAX_ADDR;
@@ -4542,7 +4542,7 @@ static void mvpp2_phy_connect(struct udevice *dev, struct mvpp2_port *port)
 
 		port->phy_dev = phy_dev;
 		if (!phy_dev) {
-			dev_err(port->phy_dev->dev, "cannot connect to phy\n");
+			dev_err(dev, "cannot connect to phy\n");
 			return;
 		}
 		phy_dev->supported &= PHY_GBIT_FEATURES;
Signature · 1 line
2.43.0
#1 lore raw
Quoted 5 lines · Vincent Jardin

Fix two NULL pointer dereferences in mvpp2_phy_connect():

1. port->phy_dev->dev is used in dev_warn() but port->phy_dev is not assigned yet (assigned later at line below).

Quoted 8 lines

2. port->phy_dev->dev is used in dev_err() inside the "if (!phy_dev)" block, which means phy_dev is NULL.

Both cases would cause a crash if the PHY detection fails or returns a generic PHY. Use the already available 'dev' parameter instead.

Fixes 9db60ee470c2 ("net: mvpp2: Convert netdev_xxx to dev_xxx")

Applied to u-boot-marvell/next

Thanks,
Stefan