MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / netdev_unregister

Function netdev_unregister

components/net/netdev/src/netdev.c:149–214  ·  view source on GitHub ↗

* This function will unregister network interface device and * delete it from network interface device list. * * @param netdev the network interface device object * * @return 0: unregistered successfully * -1: unregistered failed */

Source from the content-addressed store, hash-verified

147 * -1: unregistered failed
148 */
149int netdev_unregister(struct netdev *netdev)
150{
151 rt_slist_t *node = RT_NULL;
152 struct netdev *cur_netdev = RT_NULL;
153
154 RT_ASSERT(netdev);
155
156 if (netdev_list == RT_NULL)
157 {
158 return -RT_ERROR;
159 }
160
161 rt_spin_lock(&_spinlock);
162
163 for (node = &(netdev_list->list); node; node = rt_slist_next(node))
164 {
165 cur_netdev = rt_slist_entry(node, struct netdev, list);
166 if (cur_netdev == netdev)
167 {
168 /* find this network interface device in network interface device list */
169 if (netdev_list == netdev)
170 {
171 rt_slist_t *next = rt_slist_next(node);
172 if (next)
173 {
174 netdev_list = rt_slist_entry(next, struct netdev, list);
175 }
176 else
177 {
178 netdev_list = RT_NULL;
179 }
180 }
181 else
182 {
183 rt_slist_remove(&(netdev_list->list), &(cur_netdev->list));
184 }
185 if (netdev_default == netdev)
186 {
187 netdev_default = RT_NULL;
188 }
189 break;
190 }
191 }
192 rt_spin_unlock(&_spinlock);
193
194#if defined(SAL_USING_AF_NETLINK)
195 rtnl_ip_notify(netdev, RTM_DELLINK);
196#endif
197
198 if (netdev_default == RT_NULL)
199 {
200 netdev_set_default(netdev_list);
201 }
202
203 if (cur_netdev == netdev)
204 {
205#ifdef RT_USING_SAL
206 extern int sal_netdev_cleanup(struct netdev *netdev);

Callers 2

netdev_delFunction · 0.85

Calls 7

rt_slist_nextFunction · 0.85
rt_slist_removeFunction · 0.85
netdev_set_defaultFunction · 0.85
sal_netdev_cleanupFunction · 0.85
rt_memsetFunction · 0.85
rt_spin_lockFunction · 0.50
rt_spin_unlockFunction · 0.50

Tested by 1