[PATCH 1/1] net: phy: possible NULL dereference in fixed_phy_create()

Heinrich Schuchardt heinrich.schuchardt at canonical.com
Mon Jul 11 19:40:13 CEST 2022


We check if phydev is NULL. Only but if it is non-NULL we set one
component of phydev. But even if it is NULL we set another. We should not
dereference NULL in either case.

Fixes: e24b58f5ed4f ("net: phy: don't require PHY interface mode during PHY creation")
Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt at canonical.com>
---
 drivers/net/phy/phy.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
index 1121b99abf..945642ed93 100644
--- a/drivers/net/phy/phy.c
+++ b/drivers/net/phy/phy.c
@@ -984,10 +984,10 @@ struct phy_device *fixed_phy_create(ofnode node)
 	}
 
 	phydev = phy_device_create(NULL, 0, PHY_FIXED_ID, false);
-	if (phydev)
+	if (phydev) {
 		phydev->node = subnode;
-
-	phydev->interface = ofnode_read_phy_mode(node);
+		phydev->interface = ofnode_read_phy_mode(node);
+	}
 
 	return phydev;
 }
-- 
2.36.1



More information about the U-Boot mailing list