]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MEDIUM: mt_lists: Avoid el->prev = el->next = el
authorOlivier Houchard <ohouchard@haproxy.com>
Thu, 23 Oct 2025 12:41:23 +0000 (14:41 +0200)
committerOlivier Houchard <cognet@ci0.org>
Thu, 23 Oct 2025 12:43:51 +0000 (14:43 +0200)
Avoid setting both el->prev and el->next on the same line.
The goal is to set both el->prev and el->next to el, but a naive
compiler, such as when we're using -O0, will set el->next first, then
will set el->prev to the value of el->next, but if we're unlucky,
el->next will have been set to something else by another thread.
So explicitely set both to what we want.

This should be backported up to 2.8.

include/import/mt_list.h

index b1eb7244f39352a510251f1fbe9af939ca00097a..4c1b3e286232d129d9708dc42ce84904f5ee72af 100644 (file)
@@ -264,7 +264,8 @@ static inline __attribute__((always_inline)) unsigned long mt_list_cpu_relax(uns
  */
 static inline struct mt_list *mt_list_init(struct mt_list *el)
 {
-       el->next = el->prev = el;
+       el->next = el;
+       el->prev = el;
        return el;
 }
 
@@ -490,7 +491,8 @@ static MT_INLINE struct mt_list *mt_list_behead(struct mt_list *lh)
                        break;
                }
 
-               lh->next = lh->prev = lh;
+               lh->next = lh;
+               lh->prev = lh;
                __atomic_thread_fence(__ATOMIC_RELEASE);
 
                n->prev = p;
@@ -643,7 +645,8 @@ static MT_INLINE long mt_list_delete(struct mt_list *el)
                 * somebody may be using it already.
                 */
                if (el != n) {
-                       el->prev = el->next = el;
+                       el->prev = el;
+                       el->next = el;
                        __atomic_thread_fence(__ATOMIC_RELEASE);
                }