mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-01-18 12:52:44 +01:00
Merge pull request #7711 from miri64/gnrc_netif2/fix/fail-fast
gnrc_netif2: make gnrc_netif2_create idempotent and crash on error
This commit is contained in:
commit
9368b1deb6
@ -218,11 +218,8 @@ void gnrc_nrfmin_init(void)
|
||||
/* setup the NRFMIN driver */
|
||||
nrfmin_setup();
|
||||
#ifdef MODULE_GNRC_NETIF2
|
||||
if (!gnrc_netif2_create(stack, sizeof(stack), NRFMIN_GNRC_THREAD_PRIO,
|
||||
"nrfmin", (netdev_t *)&nrfmin_dev,
|
||||
&gnrc_nrfmin_ops)) {
|
||||
DEBUG("[nrfmin_dev] error initializing GNRC interface for nrfmin radio\n");
|
||||
}
|
||||
gnrc_netif2_create(stack, sizeof(stack), NRFMIN_GNRC_THREAD_PRIO, "nrfmin",
|
||||
(netdev_t *)&nrfmin_dev, &gnrc_nrfmin_ops);
|
||||
#else
|
||||
/* initialize the GNRC plug struct */
|
||||
plug.send = gnrc_nrfmin_send;
|
||||
|
@ -215,8 +215,11 @@ struct gnrc_netif2_ops {
|
||||
* @note If @ref DEVELHELP is defined netif_params_t::name is used as the
|
||||
* name of the network interface's thread.
|
||||
*
|
||||
* @attention Fails and crashes (assertion error with @ref DEVELHELP or
|
||||
* segmentation fault without) if `GNRC_NETIF_NUMOF` is lower than
|
||||
* the number of calls to this function.
|
||||
*
|
||||
* @return The network interface on success.
|
||||
* @return NULL, on error.
|
||||
*/
|
||||
gnrc_netif2_t *gnrc_netif2_create(char *stack, int stacksize, char priority,
|
||||
const char *name, netdev_t *dev,
|
||||
|
@ -35,8 +35,11 @@ extern "C" {
|
||||
*
|
||||
* @see @ref gnrc_netif2_create()
|
||||
*
|
||||
* @attention Fails and crashes (assertion error with @ref DEVELHELP or
|
||||
* segmentation fault without) if `GNRC_NETIF_NUMOF` is lower than
|
||||
* the number of calls to this function.
|
||||
*
|
||||
* @return The network interface on success.
|
||||
* @return NULL, on error.
|
||||
*/
|
||||
gnrc_netif2_t *gnrc_netif2_ethernet_create(char *stack, int stacksize, char priority,
|
||||
char *name, netdev_t *dev);
|
||||
|
@ -51,16 +51,14 @@ gnrc_netif2_t *gnrc_netif2_create(char *stack, int stacksize, char priority,
|
||||
int res;
|
||||
|
||||
for (int i = 0; i < GNRC_NETIF_NUMOF; i++) {
|
||||
if (_netifs[i].ops == NULL) {
|
||||
if (_netifs[i].dev == netdev) {
|
||||
return &_netifs[i];
|
||||
}
|
||||
if ((netif == NULL) && (_netifs[i].ops == NULL)) {
|
||||
netif = &_netifs[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (netif == NULL) {
|
||||
LOG_ERROR("gnrc_netif2: can not allocate network interface.\n"
|
||||
"Set GNRC_NETIF_NUMOF to a higher value\n");
|
||||
return NULL;
|
||||
}
|
||||
assert(netif != NULL);
|
||||
rmutex_init(&netif->mutex);
|
||||
netif->ops = ops;
|
||||
assert(netif->dev == NULL);
|
||||
|
@ -91,7 +91,6 @@ static inline void _test_init(gnrc_netif2_t *netif)
|
||||
|
||||
static void test_creation(void)
|
||||
{
|
||||
char test_stack[4];
|
||||
gnrc_netif2_t *ptr = NULL;
|
||||
|
||||
TEST_ASSERT_EQUAL_INT(0, gnrc_netif2_numof());
|
||||
@ -131,8 +130,6 @@ static void test_creation(void)
|
||||
TEST_ASSERT_NULL((ptr = gnrc_netif2_iter(ptr)));
|
||||
}
|
||||
TEST_ASSERT(init_called);
|
||||
TEST_ASSERT_NULL(gnrc_netif2_create(test_stack, 4, GNRC_NETIF2_PRIO,
|
||||
"netif", NULL, &default_ops));
|
||||
}
|
||||
|
||||
static void test_get_by_pid(void)
|
||||
|
Loading…
Reference in New Issue
Block a user