[PATCH] Add list_for_each_entry_safe_reverse()
authorDavid Howells <dhowells@redhat.com>
Tue, 10 Jan 2006 04:51:31 +0000 (20:51 -0800)
committerLinus Torvalds <torvalds@g5.osdl.org>
Tue, 10 Jan 2006 16:01:24 +0000 (08:01 -0800)
Add list_for_each_entry_safe_reverse() to linux/list.h

This is needed by unmerged cachefs and be an as-yet-unreviewed
device_shutdown() fix.

Signed-off-by: David Howells <dhowells@redhat.com>
Cc: Patrick Mochel <mochel@digitalimplant.org>
Cc: Greg KH <greg@kroah.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
include/linux/list.h

index 8e3388284530093dc71a1231c263d4436cf8a88d..945daa1f13dd05d6a7ad95e6022108a824d6a3dd 100644 (file)
@@ -435,6 +435,20 @@ static inline void list_splice_init(struct list_head *list,
             &pos->member != (head);                                            \
             pos = n, n = list_entry(n->member.next, typeof(*n), member))
 
+/**
+ * list_for_each_entry_safe_reverse - iterate backwards over list of given type safe against
+ *                                   removal of list entry
+ * @pos:       the type * to use as a loop counter.
+ * @n:         another type * to use as temporary storage
+ * @head:      the head for your list.
+ * @member:    the name of the list_struct within the struct.
+ */
+#define list_for_each_entry_safe_reverse(pos, n, head, member)         \
+       for (pos = list_entry((head)->prev, typeof(*pos), member),      \
+               n = list_entry(pos->member.prev, typeof(*pos), member); \
+            &pos->member != (head);                                    \
+            pos = n, n = list_entry(n->member.prev, typeof(*n), member))
+
 /**
  * list_for_each_rcu   -       iterate over an rcu-protected list
  * @pos:       the &struct list_head to use as a loop counter.