mirror of
https://github.com/apache/nuttx.git
synced 2026-05-22 05:42:05 +08:00
Networking: The network device list was protected by a re-entrant semaphore. With the recent change to support network device callback, the network stack needs to access the network device list too. Some drivers, however, run the network stack from the interrupt level -- this is bad but a fact in the current state. Of course,those drivers are unable to take the semaphore and will assert.
The solution here is to eliminate the device devices semaphore altogether. This eliminates netdev_semtake() and netdev_semgive() and replaces them with net_lock() and net_unlock() which have larger scope as needed for this purpose.
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
/****************************************************************************
|
||||
* net/netdev/netdev_default.c
|
||||
*
|
||||
* Copyright (C) 2014 Gregory Nutt. All rights reserved.
|
||||
* Copyright (C) 2014-2015 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -41,6 +41,8 @@
|
||||
#if defined(CONFIG_NET) && CONFIG_NSOCKET_DESCRIPTORS > 0
|
||||
|
||||
#include <nuttx/net/netdev.h>
|
||||
|
||||
#include "utils/utils.h"
|
||||
#include "netdev/netdev.h"
|
||||
|
||||
/****************************************************************************
|
||||
@@ -98,10 +100,11 @@
|
||||
FAR struct net_driver_s *netdev_default(void)
|
||||
{
|
||||
FAR struct net_driver_s *dev;
|
||||
net_lock_t save;
|
||||
|
||||
/* Examine each registered network device */
|
||||
|
||||
netdev_semtake();
|
||||
save = net_lock();
|
||||
for (dev = g_netdevices; dev; dev = dev->flink)
|
||||
{
|
||||
/* Is the interface in the "up" state? */
|
||||
@@ -112,12 +115,12 @@ FAR struct net_driver_s *netdev_default(void)
|
||||
* state.
|
||||
*/
|
||||
|
||||
netdev_semgive();
|
||||
net_unlock(save);
|
||||
return dev;
|
||||
}
|
||||
}
|
||||
|
||||
netdev_semgive();
|
||||
net_unlock(save);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user