
Or we may get load access faults afterward.
The `phydev` field on axi-ethernet’s private struct is not set on a failed phy_connect():
axi_emac_probe() => axiemac_phy_init() => priv->phydev = phy_connect() <--- may fail
However, all of the following calls on `axi_emac_ops` assume a valid `phydev` pointer. For example:
axiemac_start() => setup_phy() => phy_startup() => if (phydev->drv->startup) <--- deref of phydev return phydev->drv->startup(phydev);
Thus, it would be better to fail at the driver probe and let u-boot handle the rest (e.g. probe the driver again if needed), rather than having access faults.
Signed-off-by: Andy Chiu andy.chiu@sifive.com Reviewed-by: Greentime Hu greentime.hu@sifive.com ---
drivers/net/xilinx_axi_emac.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/drivers/net/xilinx_axi_emac.c b/drivers/net/xilinx_axi_emac.c index dbda6c70d8..08322aff88 100644 --- a/drivers/net/xilinx_axi_emac.c +++ b/drivers/net/xilinx_axi_emac.c @@ -782,10 +782,16 @@ static int axiemac_setup_emac(struct udevice *dev)
ret = mdio_register_seq(priv->bus, dev_seq(dev)); if (ret) - return ret; + goto fail;
- axiemac_phy_init(dev); + ret = axiemac_phy_init(dev); + if (ret) + goto fail_free_mdio;
+fail_free_mdio: + mdio_unregister(priv->bus); + mdio_free(priv->bus); +fail: return ret; }