From 2068ec4f89af0bb1f8540ddd162e3c762ccebd89 Mon Sep 17 00:00:00 2001 From: Olivier Houchard Date: Thu, 17 Oct 2019 17:46:01 +0200 Subject: [PATCH] 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. --- include/common/mini-clist.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/include/common/mini-clist.h b/include/common/mini-clist.h index bb794e3d6b..e29451148c 100644 --- a/include/common/mini-clist.h +++ b/include/common/mini-clist.h @@ -307,6 +307,8 @@ struct cond_wordlist { * 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 * 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) ({ \ struct mt_list *lh = (_lh); \ @@ -336,7 +338,7 @@ struct cond_wordlist { (lh)->next = (lh); \ (lh)->prev = (lh); \ _n->prev = _p; \ - _p->next = _n; \ + _p->next = NULL; \ __ha_barrier_store(); \ break; \ } \