diff --git a/net/netdev/netdev_register.c b/net/netdev/netdev_register.c index 3694db5aad2..3ce1732fc6c 100644 --- a/net/netdev/netdev_register.c +++ b/net/netdev/netdev_register.c @@ -240,6 +240,7 @@ static int get_ifindex(void) int netdev_register(FAR struct net_driver_s *dev, enum net_lltype_e lltype) { + FAR struct net_driver_s **last; FAR char devfmt_str[IFNAMSIZ]; FAR const char *devfmt; uint16_t pktsize = 0; @@ -428,8 +429,15 @@ int netdev_register(FAR struct net_driver_s *dev, enum net_lltype_e lltype) /* Add the device to the list of known network devices */ - dev->flink = g_netdevices; - g_netdevices = dev; + last = &g_netdevices; + while (*last) + { + last = &((*last)->flink); + } + + *last = dev; + + dev->flink = NULL; #ifdef CONFIG_NET_IGMP /* Configure the device for IGMP support */