[U-Boot] [PATCH] Check eth_get_dev() for null on NetLoop entry

Josef Holzmayr holzmayr at rsi-elektrotechnik.de
Fri Nov 23 12:11:14 CET 2012


If using an usb ethernet interface and starting usb is forgot,
any attempt to use ethernet will try to init networking and dereference
eth_get_dev() to null.

This patch adds a check and aborts in case of a null pointer.

---
 net/net.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/net/net.c b/net/net.c
index 82c4cc9..1301e6b 100644
--- a/net/net.c
+++ b/net/net.c
@@ -313,6 +313,17 @@ int NetLoop(enum proto_t protocol)
 	NetTryCount = 1;
 	debug_cond(DEBUG_INT_STATE, "--- NetLoop Entry\n");
 
+	/* If we do not check, initialisation will dereference NULL */
+	if (!eth_get_dev())
+	{
+#ifdef CONFIG_USB_HOST_ETHER
+		printf("Ethernet not available. Have you run \"usb start\" already?\n");
+#else
+		printf("Ethernet not available.\n");
+#endif
+		return -1;
+	}
+
 	bootstage_mark_name(BOOTSTAGE_ID_ETH_START, "eth_start");
 	net_init();
 	if (eth_is_on_demand_init() || protocol != NETCONS) {
-- 
1.8.0


-- 
_____________________________________________________________
R-S-I Elektrotechnik GmbH & Co. KG
Woelkestrasse 11
D-85301 Schweitenkirchen
Fon: +49 8444 9204-0
Fax: +49 8444 9204-50
www.rsi-elektrotechnik.de

_____________________________________________________________
Amtsgericht Ingolstadt - GmbH: HRB 191328 - KG: HRA 170363
Geschäftsführer: Dr.-Ing. Michael Sorg, Dipl.-Ing. Franz Sorg
USt-IdNr.: DE 128592548



More information about the U-Boot mailing list