1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-01-18 12:52:44 +01:00

gnrc_netif2: make gnrc_netif2_create idempotent and crash on error

This commit is contained in:
Martine Lenders 2017-10-10 21:17:32 +02:00
parent c8a025635a
commit 3929550ea3
3 changed files with 13 additions and 9 deletions

View File

@ -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,

View File

@ -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);

View File

@ -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);