[PATCH 1/3] net: xilinx: fix load access fault

Andy Chiu andy.chiu at sifive.com
Thu Jan 20 08:34:18 CET 2022


From: Greentime Hu <greentime.hu at sifive.com>

phy_connect() may fail by returning a NULL pointer. Thus,
axiemac_phy_init() should handle the case or we may get an access
fault when it tries to dereference it.

Signed-off-by: Greentime Hu <greentime.hu at sifive.com>
Reviewed-by: Andy Chiu <andy.chiu at sifive.com>
Signed-off-by: Andy Chiu <andy.chiu at sifive.com>
---

 drivers/net/xilinx_axi_emac.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/net/xilinx_axi_emac.c b/drivers/net/xilinx_axi_emac.c
index 2ec76d0f52..3117dae05e 100644
--- a/drivers/net/xilinx_axi_emac.c
+++ b/drivers/net/xilinx_axi_emac.c
@@ -312,6 +312,10 @@ static int axiemac_phy_init(struct udevice *dev)
 
 	/* Interface - look at tsec */
 	phydev = phy_connect(priv->bus, priv->phyaddr, dev, priv->interface);
+	if (!phydev) {
+		printf("phy_connect failed\n");
+		return -ENODEV;
+	}
 
 	phydev->supported &= supported;
 	phydev->advertising = phydev->supported;
-- 
2.34.1



More information about the U-Boot mailing list