netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] list.h: add list_for_each_struct_entry macro
@ 2010-01-18 16:23 Jiri Pirko
  2010-01-18 17:17 ` Ben Hutchings
  0 siblings, 1 reply; 5+ messages in thread
From: Jiri Pirko @ 2010-01-18 16:23 UTC (permalink / raw)
  To: linux-kernel; +Cc: bhutchings, davem, netdev

When preparing to upcoming migration of mc_list (list of multicast MACs)
to list_head, the need of traversing the list over one structure member
appeared. I thought I'll do it locally but I decided that an intruduction
the macro in list.h would be much clearer. Please kindly for a review.

Jirka

Signed-off-by: Jiri Pirko <jpirko@redhat.com>

diff --git a/include/linux/list.h b/include/linux/list.h
index 969f6e9..8350a94 100644
--- a/include/linux/list.h
+++ b/include/linux/list.h
@@ -420,6 +420,22 @@ static inline void list_splice_tail_init(struct list_head *list,
 	     pos = list_entry(pos->member.prev, typeof(*pos), member))
 
 /**
+ * list_for_each_struct_entry  -       iterate over list of given type using
+ *                                     the struct member.
+ * @pos:       the type * to use as a loop cursor.
+ * @head:      the head for your list.
+ * @type:      the type of the struct.
+ * @posmember: the name ot the loop cursor within the struct.
+ * @member:    the name of the list_struct within the struct.
+ */
+#define list_for_each_struct_entry(pos, head, type, posmember, member)		\
+	for (pos = list_entry((head)->next, type, member)->posmember;		\
+	     prefetch(container_of(pos, type, posmember)->member.next),		\
+	     &container_of(pos, type, posmember)->member != (head);		\
+	     pos = list_entry(container_of(pos, type, posmember)->member.next,	\
+	     type, member)->posmember)
+
+/**
  * list_prepare_entry - prepare a pos entry for use in list_for_each_entry_continue()
  * @pos:	the type * to use as a start point
  * @head:	the head of the list

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2010-01-18 21:30 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-01-18 16:23 [PATCH] list.h: add list_for_each_struct_entry macro Jiri Pirko
2010-01-18 17:17 ` Ben Hutchings
2010-01-18 21:07   ` Jiri Pirko
2010-01-18 21:14     ` Ben Hutchings
2010-01-18 21:30       ` Jiri Pirko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).