[riot-notifications] [RIOT-OS/RIOT] sys/net/gnrc/netif: make gnrc_netif_create() blocking to avoid race condition (#16527)

benpicco notifications at github.com
Fri Jun 4 17:53:20 CEST 2021

The RIOT community cares a lot about code quality.
Therefore, before describing what your contribution is about, we would like
you to make sure that your modifications are compliant with the RIOT
coding conventions, see https://github.com/RIOT-OS/RIOT/wiki/Coding-conventions.

### Contribution description

Make `gnrc_netif_create()` block until the interface is created and registered.
This avoids a race condition where after calling `gnrc_netif_init_devs()` not all interfaces are available yet when iterating through the list of interfaces with `gnrc_netif_iter()`.

### Testing procedure

Replace the `auto_init_gnrc_netif` module with `gnrc_netif_init_devs` to manually initialize the network interfaces.
Then iterate all interfaces after having called `gnrc_netif_init_devs()`:

/* enable network interfaces */

/* iterate all interfaces */
gnrc_netif_t *netif = NULL;
while (netif = gnrc_netif_iter(netif)) {
    puts("network interface found");

Without this patch, this will 'find' no network interfaces (if the driver uses sleep inside it's init path), but after a delay all interfaces will be printed.

With this patch `gnrc_netif_init_devs()` will only return once all interfaces are in a defined state.

### Issues/PRs references

Examples: Fixes #1234. See also #5678. Depends on PR #9876.

Please use keywords (e.g., fixes, resolve) with the links to the issues you
resolved, this way they will be automatically closed when your pull request
is merged. See https://help.github.com/articles/closing-issues-using-keywords/.

You can view, comment on, or merge this pull request online at:


-- Commit Summary --

  * sys/net/gnrc/netif: make gnrc_netif_create() blocking

-- File Changes --

    M sys/net/gnrc/netif/gnrc_netif.c (10)

-- Patch Links --


You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.riot-os.org/pipermail/notifications/attachments/20210604/4d901360/attachment.htm>

More information about the notifications mailing list