[U-Boot] [PATCH 3/6] driver: net: fsl-mc: fix error handing in init_phy

Joe Hershberger joe.hershberger at ni.com
Wed Jul 25 20:04:36 UTC 2018


On Fri, Jul 13, 2018 at 9:40 AM, Pankaj Bansal <pankaj.bansal at nxp.com> wrote:
> if an error occurs during init_phy, we should free the phydev structure
> which has been allocated by phy_connect.
>
> Signed-off-by: Pankaj Bansal <pankaj.bansal at nxp.com>
> ---
>  drivers/net/ldpaa_eth/ldpaa_eth.c | 11 ++++++++++-
>  1 file changed, 10 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/net/ldpaa_eth/ldpaa_eth.c b/drivers/net/ldpaa_eth/ldpaa_eth.c
> index fbc724fc33..8fcb948ee8 100644
> --- a/drivers/net/ldpaa_eth/ldpaa_eth.c
> +++ b/drivers/net/ldpaa_eth/ldpaa_eth.c
> @@ -23,6 +23,7 @@ static int init_phy(struct eth_device *dev)
>         struct ldpaa_eth_priv *priv = (struct ldpaa_eth_priv *)dev->priv;
>         struct phy_device *phydev = NULL;
>         struct mii_dev *bus;
> +       int ret;
>
>         bus = wriop_get_mdio(priv->dpmac_id);
>         if (bus == NULL)
> @@ -37,7 +38,15 @@ static int init_phy(struct eth_device *dev)
>
>         wriop_set_phy_dev(priv->dpmac_id, phydev);
>
> -       return phy_config(phydev);
> +       ret = phy_config(phydev);
> +
> +       if (ret) {
> +               free(phydev);
> +               phydev = NULL;

This seems odd. It's a local variable... why not just pass NULL into
wriop_set_phy_dev()? That seems clearer.

> +               wriop_set_phy_dev(priv->dpmac_id, phydev);
> +       }
> +
> +       return ret;
>  }
>  #endif
>
> --
> 2.17.1
>
> _______________________________________________
> U-Boot mailing list
> U-Boot at lists.denx.de
> https://lists.denx.de/listinfo/u-boot


More information about the U-Boot mailing list