Re: [PATCH] add safe version of list_for_each_entry() to list.h

Kevin Corry (corryk@us.ibm.com)
Fri, 4 Oct 2002 08:51:12 -0500


On Friday 04 October 2002 08:58, Christoph Hellwig wrote:
> > + */
> > +#define list_for_each_entry_safe(pos, n, head, member) \
> > + for (pos = list_entry((head)->next, typeof(*pos), member), \
> > + n = list_entry(pos->member.next, typeof(*pos), member); \
> > + &pos->member != (head); \
> > + pos = n, \
> > + n = list_entry(pos->member.next, typeof(*pos), member))
>
> Identation looks a little strange..

Dammit. Forgot to insert the patch. Here goes again.

-- 
Kevin Corry
corryk@us.ibm.com
http://evms.sourceforge.net/

====================================================== diff -Naur linux-2.5.40a/include/linux/list.h linux-2.5.40b/include/linux/list.h --- linux-2.5.40a/include/linux/list.h Fri Oct 4 08:45:54 2002 +++ linux-2.5.40b/include/linux/list.h Fri Oct 4 08:45:31 2002 @@ -137,6 +137,15 @@ return head->next == head; } +/** + * list_member - tests whether a list member is currently on a list + * @member: member to evaulate + */ +static inline int list_member(struct list_head *member) +{ + return member->next && member->prev; +} + static inline void __list_splice(struct list_head *list, struct list_head *head) { @@ -240,6 +249,20 @@ &pos->member != (head); \ pos = list_entry(pos->member.next, typeof(*pos), member), \ prefetch(pos->member.next)) + +/** + * list_for_each_entry_safe - iterate over list 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(pos, n, head, member) \ + for (pos = list_entry((head)->next, typeof(*pos), member), \ + n = list_entry(pos->member.next, typeof(*pos), member); \ + &pos->member != (head); \ + pos = n, \ + n = list_entry(pos->member.next, typeof(*pos), member)) #endif /* __KERNEL__ || _LVM_H_INCLUDE */ - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/