linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Re: [PATCH] add safe version of list_for_each_entry() to list.h
@ 2002-10-04 16:40 Mark Peloquin
  0 siblings, 0 replies; 11+ messages in thread
From: Mark Peloquin @ 2002-10-04 16:40 UTC (permalink / raw)
  To: Matthew Wilcox; +Cc: linux-kernel


On 10/04/2002 at 11:00 AM, Matthew Wilcox wrote:

> That behaviour for list_del is new and, IMNSHO, bogus.  There's now
_zero_
> gain in using list_del instead of list_del_init.

The only gain I've noticed is when the container
object is memset it gives implicit initialization
if one uses list_del.

> akpm changed it about
> 5 months ago with a comment that says:

> "list_head debugging"

> so i think it's pretty safe to assume that this behaviour will not
> remain into 2.6.  if you think you want list_member, use list_del_init
> and list_empty() instead.

I wasn't aware this was somewhat recently added item
for debug and will switch to list_del_init().

Thanks for bring this to my attention!



^ permalink raw reply	[flat|nested] 11+ messages in thread
* Re: [PATCH] add safe version of list_for_each_entry() to list.h
@ 2002-10-04 15:48 Mark Peloquin
  2002-10-04 16:00 ` Matthew Wilcox
  0 siblings, 1 reply; 11+ messages in thread
From: Mark Peloquin @ 2002-10-04 15:48 UTC (permalink / raw)
  To: Matthew Wilcox; +Cc: linux-kernel


On 10/04/2002 at 10:05 AM, Matthew Wilcox wrote:
> Your list_member macro:

> +static inline int list_member(struct list_head *member)
> +{
> + return ((!member->next || !member->prev) ? 0 : 1);
> +}

> seems wrong to me.  A list head which has been removed from its list
using
> list_del() still points to its old prev & next entries.  If removed using
> list_del_init(), those pointers are reinitialised to point at itself.
> ie you only need list_empty().  Are you abusing list.h somehow?

list_empty() can be used on check list heads *or*
to check if a list element is currently in a list,
assuming the coder uses list_del_init(). However,
if the coder chooses to use list_del() [which sets
the prev and next fields to 0] instead, there is no
corresponding function to indicate if that element
is currently on a list. This function does that.

Mark



^ permalink raw reply	[flat|nested] 11+ messages in thread
* Re: [PATCH] add safe version of list_for_each_entry() to list.h
@ 2002-10-04 15:05 Matthew Wilcox
  0 siblings, 0 replies; 11+ messages in thread
From: Matthew Wilcox @ 2002-10-04 15:05 UTC (permalink / raw)
  To: Mark Peloquin; +Cc: linux-kernel


Your list_member macro:

+static inline int list_member(struct list_head *member)
+{
+ return ((!member->next || !member->prev) ? 0 : 1);
+}

seems wrong to me.  A list head which has been removed from its list using
list_del() still points to its old prev & next entries.  If removed using
list_del_init(), those pointers are reinitialised to point at itself.
ie you only need list_empty().  Are you abusing list.h somehow?

-- 
Revolutions do not require corporate support.

^ permalink raw reply	[flat|nested] 11+ messages in thread
* [PATCH] add safe version of list_for_each_entry() to list.h
@ 2002-10-03 23:42 Mark Peloquin
  2002-10-03 23:44 ` Greg KH
  0 siblings, 1 reply; 11+ messages in thread
From: Mark Peloquin @ 2002-10-03 23:42 UTC (permalink / raw)
  To: torvalds; +Cc: linux-kernel, evms-devel

Please consider adding the following patch to list.h.

The following patch adds list_for_each_entry_safe() and
list_member() to list.h.

- List_for_each_entry_safe adds a removal-safe version of this macro.
- List_member indicates if the container object is currently in a list.

Thanks.
Mark

diff -Naur old/include/linux/list.h new/include/linux/list.h
--- old/include/linux/list.h  Thu Oct  3 18:06:42 2002
+++ new/include/linux/list.h  Thu Oct  3 18:10:46 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) ? 0 : 1);
+}
+
 static inline void __list_splice(struct list_head *list,
                         struct list_head *head)
 {
@@ -241,6 +250,20 @@
           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 */

 #endif



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

end of thread, other threads:[~2002-10-04 16:29 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-10-04 16:40 [PATCH] add safe version of list_for_each_entry() to list.h Mark Peloquin
  -- strict thread matches above, loose matches on Subject: below --
2002-10-04 15:48 Mark Peloquin
2002-10-04 16:00 ` Matthew Wilcox
2002-10-04 16:33   ` Andrew Morton
2002-10-04 15:05 Matthew Wilcox
2002-10-03 23:42 Mark Peloquin
2002-10-03 23:44 ` Greg KH
2002-10-04  0:25   ` Kevin Corry
2002-10-04 13:58     ` Christoph Hellwig
2002-10-04 13:48       ` Kevin Corry
2002-10-04 13:51       ` Kevin Corry

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).