llist: fix/simplify llist_add() and llist_add_batch()
[cascardo/linux.git] / include / linux / llist.h
index a5199f6..3e2b969 100644 (file)
@@ -151,18 +151,13 @@ static inline struct llist_node *llist_next(struct llist_node *node)
  */
 static inline bool llist_add(struct llist_node *new, struct llist_head *head)
 {
-       struct llist_node *entry, *old_entry;
-
-       entry = head->first;
-       for (;;) {
-               old_entry = entry;
-               new->next = entry;
-               entry = cmpxchg(&head->first, old_entry, new);
-               if (entry == old_entry)
-                       break;
-       }
-
-       return old_entry == NULL;
+       struct llist_node *first;
+
+       do {
+               new->next = first = ACCESS_ONCE(head->first);
+       } while (cmpxchg(&head->first, first, new) != first);
+
+       return !first;
 }
 
 /**