From a82bc64a340d88c46affb3cc93b89d9e7d0022a5 Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Mon, 1 Feb 2021 19:13:41 +0100 Subject: [PATCH] sys/net/gnrc/netif: only register netif after init was successful If we call `netif_register()` before we can be sure that the interface can be configured, a 'zombie' interface remains in the list, causing all kinds of trouble down the line. Only call `netif_register()` if `init()` was successful. --- sys/net/gnrc/netif/gnrc_netif.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/sys/net/gnrc/netif/gnrc_netif.c b/sys/net/gnrc/netif/gnrc_netif.c index 3ea3b5abe1..8d1fa45626 100644 --- a/sys/net/gnrc/netif/gnrc_netif.c +++ b/sys/net/gnrc/netif/gnrc_netif.c @@ -74,7 +74,6 @@ int gnrc_netif_create(gnrc_netif_t *netif, char *stack, int stacksize, #endif rmutex_init(&netif->mutex); netif->ops = ops; - netif_register((netif_t*) netif); assert(netif->dev == NULL); netif->dev = netdev; res = thread_create(stack, stacksize, priority, THREAD_CREATE_STACKTEST, @@ -1610,14 +1609,9 @@ static void *_gnrc_netif_thread(void *args) res = dev->driver->init(dev); if (res < 0) { LOG_ERROR("gnrc_netif: netdev init failed: %d\n", res); - /* unregister this netif instance */ - netif->ops = NULL; - netif->pid = KERNEL_PID_UNDEF; - netif->dev = NULL; - dev->event_callback = NULL; - dev->context = NULL; return NULL; } + netif_register(&netif->netif); _configure_netdev(dev); netif->ops->init(netif); #if DEVELHELP