Skip to contentSkip to conversation

nitrogen6x: Fix the error handling in board_eth_init()

PATCH New Fabio Estevam 2 participants 3 messages Sep 11, 2015

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 nitrogen6x: Fix the error handling in board_eth_init()

From: Fabio Estevam <[email protected]>

We should not return 0 on failure, so return a negative error code instead.

Also centralize the error path so that is easier to follow.

---
 board/boundary/nitrogen6x/nitrogen6x.c | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)
board/boundary/nitrogen6x/nitrogen6x.c +11 -8
index d46b8db..104d71f 100644
@@ -387,20 +387,17 @@ int board_eth_init(bd_t *bis)
 #ifdef CONFIG_FEC_MXC
 	bus = fec_get_miibus(base, -1);
 	if (!bus)
-		return 0;
+		return -EINVAL;
 	/* scan phy 4,5,6,7 */
 	phydev = phy_find_by_mask(bus, (0xf << 4), PHY_INTERFACE_MODE_RGMII);
 	if (!phydev) {
-		free(bus);
-		return 0;
+		ret = -EINVAL;
+		goto free_bus;
 	}
 	printf("using phy@%d\n", phydev->addr);
 	ret  = fec_probe(bis, -1, base, bus, phydev);
-	if (ret) {
-		printf("FEC MXC: %s:failed\n", __func__);
-		free(phydev);
-		free(bus);
-	}
+	if (ret)
+		goto free_phydev;
 #endif
 
 #ifdef CONFIG_CI_UDC
@@ -408,6 +405,12 @@ int board_eth_init(bd_t *bis)
 	usb_eth_initialize(bis);
 #endif
 	return 0;
+
+free_phydev:
+	free(phydev);
+free_bus:
+	free(bus);
+	return ret;
 }
 
 static void setup_buttons(void)
Signature · 1 line
1.9.1
#1 lore raw

PATCH 2/2 ot1200: Fix the error handling in board_eth_init()

From: Fabio Estevam <[email protected]>

We should not return 0 on failure, so return a negative error code instead.

Also centralize the error path so that is easier to follow.

Cc Christian Gmeiner <[email protected]>
---
 board/bachmann/ot1200/ot1200.c | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)
board/bachmann/ot1200/ot1200.c +12 -8
index 2237b7a..eeced79 100644
@@ -305,13 +305,13 @@ int board_eth_init(bd_t *bis)
 
 	bus = fec_get_miibus(base, -1);
 	if (!bus)
-		return 0;
+		return -EINVAL;
 
 	/* scan phy 0 and 5 */
 	phydev = phy_find_by_mask(bus, 0x21, PHY_INTERFACE_MODE_RGMII);
 	if (!phydev) {
-		free(bus);
-		return 0;
+		ret = -EINVAL;
+		goto free_bus;
 	}
 
 	/* depending on the phy address we can detect our board version */
@@ -322,12 +322,16 @@ int board_eth_init(bd_t *bis)
 
 	printf("using phy at %d\n", phydev->addr);
 	ret = fec_probe(bis, -1, base, bus, phydev);
-	if (ret) {
-		printf("FEC MXC: %s:failed\n", __func__);
-		free(phydev);
-		free(bus);
-	}
+	if (ret)
+		goto free_phydev;
+
 	return 0;
+
+free_phydev:
+	free(phydev);
+free_bus:
+	free(bus);
+	return ret;
 }
 
 int board_init(void)
Signature · 1 line
1.9.1
#2 lore raw

PATCH 1/2 nitrogen6x: Fix the error handling in board_eth_init()

In reply to Fabio Estevam
Quoted 5 lines · Fabio Estevam

From: Fabio Estevam <[email protected]>

We should not return 0 on failure, so return a negative error code instead.

Quoted 7 lines

Also centralize the error path so that is easier to follow.

---
 board/boundary/nitrogen6x/nitrogen6x.c | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)