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

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) {
participants (1)
-
Josef Holzmayr