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

Pankaj Bansal pankaj.bansal at nxp.com
Wed Oct 10 08:28:00 UTC 2018


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>
Acked-by: Joe Hershberger <joe.hershberger at ni.com>
---

Notes:
    V3:
     - No change
    V2:
     - after free phydev just pass NULL into wriop_set_phy_dev()

 drivers/net/ldpaa_eth/ldpaa_eth.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ldpaa_eth/ldpaa_eth.c b/drivers/net/ldpaa_eth/ldpaa_eth.c
index ca3459cc33..f122e945a4 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,14 @@ 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);
+		wriop_set_phy_dev(priv->dpmac_id, NULL);
+	}
+
+	return ret;
 }
 #endif
 
-- 
2.17.1



More information about the U-Boot mailing list