diff --git a/sys/net/gnrc/netif/gnrc_netif.c b/sys/net/gnrc/netif/gnrc_netif.c index 7e9527a5ed..0eb6113d48 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; @@ -1665,14 +1664,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 diff --git a/sys/net/netif/netif.c b/sys/net/netif/netif.c index 572cbee768..1344febdf4 100644 --- a/sys/net/netif/netif.c +++ b/sys/net/netif/netif.c @@ -17,6 +17,7 @@ #include #include "errno.h" +#include "irq.h" #include "net/netif.h" #include "utlist.h" @@ -24,11 +25,14 @@ static list_node_t netif_list; int netif_register(netif_t *netif) { - if(netif == NULL) { + if (netif == NULL) { return -EINVAL; } + unsigned state = irq_disable(); list_add(&netif_list, &netif->node); + irq_restore(state); + return 0; } @@ -59,9 +63,9 @@ netif_t *netif_get_by_name(const char *name) char tmp[CONFIG_NETIF_NAMELENMAX]; - while(node) { + while (node) { netif_get_name((netif_t *)node, tmp); - if(strncmp(name, tmp, CONFIG_NETIF_NAMELENMAX) == 0) { + if (strncmp(name, tmp, CONFIG_NETIF_NAMELENMAX) == 0) { return (netif_t *)node; } node = node->next;