[PATCH 3/3] net: xilinx: Force a probe failure if it cannot setup phy

Andy Chiu andy.chiu at sifive.com
Wed Feb 9 14:33:02 CET 2022


Dear Maintainers,

I am sending this email to check if this patch was missed. I would be
really appreciated if I get any suggestion from you, thanks!

Best regards
Andy

On Thu, Jan 20, 2022 at 3:35 PM Andy Chiu <andy.chiu at sifive.com> wrote:
>
> 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 at sifive.com>
> Reviewed-by: Greentime Hu <greentime.hu at 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;
>  }
>
> --
> 2.34.1
>


More information about the U-Boot mailing list