From 70f6eb232ace2d5d436ef6c8cadd4d5b1f3b505a Mon Sep 17 00:00:00 2001 From: "chao.an" Date: Tue, 25 May 2021 14:49:32 +0800 Subject: [PATCH] net/dev: link the net device as order of registration Signed-off-by: chao.an --- net/netdev/netdev_register.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/net/netdev/netdev_register.c b/net/netdev/netdev_register.c index 3694db5aad..3ce1732fc6 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 */