BUG/MEDIUM: lists: Handle 1-element-lists in MT_LIST_BEHEAD().

In MT_LIST_BEHEAD(), explicitely set the next element of the prev to NULL,
instead of setting it to the prev of the next. If we only had one element,
then we'd set the next and the prev to the element itself, and thus it would
make the element appear to be outside any list.
This commit is contained in:
Olivier Houchard 2019-10-17 17:46:01 +02:00 committed by Olivier Houchard
parent ba0c53ef71
commit 2068ec4f89
1 changed files with 3 additions and 1 deletions

View File

@ -307,6 +307,8 @@ struct cond_wordlist {
* and the list is closed. If the list was empty, NULL is returned. This may * and the list is closed. If the list was empty, NULL is returned. This may
* exclusively be used with lists modified by MT_LIST_ADD/MT_LIST_ADDQ. This * exclusively be used with lists modified by MT_LIST_ADD/MT_LIST_ADDQ. This
* is incompatible with MT_LIST_DEL run concurrently. * is incompatible with MT_LIST_DEL run concurrently.
* If there's at least one element, the next of the last element will always
* be NULL.
*/ */
#define MT_LIST_BEHEAD(_lh) ({ \ #define MT_LIST_BEHEAD(_lh) ({ \
struct mt_list *lh = (_lh); \ struct mt_list *lh = (_lh); \
@ -336,7 +338,7 @@ struct cond_wordlist {
(lh)->next = (lh); \ (lh)->next = (lh); \
(lh)->prev = (lh); \ (lh)->prev = (lh); \
_n->prev = _p; \ _n->prev = _p; \
_p->next = _n; \ _p->next = NULL; \
__ha_barrier_store(); \ __ha_barrier_store(); \
break; \ break; \
} \ } \