1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-12-25 06:23:53 +01:00

Merge pull request #15907 from benpicco/gnrc_netif-register

sys/net/gnrc/netif: only register netif after init was successful
This commit is contained in:
benpicco 2021-03-16 16:26:06 +01:00 committed by GitHub
commit 8ca676aa6e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 10 deletions

View File

@ -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

View File

@ -17,6 +17,7 @@
#include <string.h>
#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;