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 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:48 [PATCH] add safe version of list_for_each_entry() to list.h Mark Peloquin
@ 2002-10-04 16:00 ` Matthew Wilcox
  2002-10-04 16:33   ` Andrew Morton
  0 siblings, 1 reply; 11+ messages in thread
From: Matthew Wilcox @ 2002-10-04 16:00 UTC (permalink / raw)
  To: Mark Peloquin; +Cc: Matthew Wilcox, linux-kernel

On Fri, Oct 04, 2002 at 10:48:33AM -0500, Mark Peloquin wrote:
> 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.

That behaviour for list_del is new and, IMNSHO, bogus.  There's now _zero_
gain in using list_del instead of list_del_init.  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.

-- 
Revolutions do not require corporate support.

^ 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 16:00 ` Matthew Wilcox
@ 2002-10-04 16:33   ` Andrew Morton
  0 siblings, 0 replies; 11+ messages in thread
From: Andrew Morton @ 2002-10-04 16:33 UTC (permalink / raw)
  To: Matthew Wilcox; +Cc: Mark Peloquin, linux-kernel

Matthew Wilcox wrote:
> 
> On Fri, Oct 04, 2002 at 10:48:33AM -0500, Mark Peloquin wrote:
> > 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.
> 
> That behaviour for list_del is new and, IMNSHO, bogus.  There's now _zero_
> gain in using list_del instead of list_del_init.  akpm changed it about
> 5 months ago with a comment that says:
> 
> "list_head debugging"
> 

It doesn't seem to have caught anyone out, so I guess we can
put it back now.  I'll do a patch.

^ 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 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: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

* Re: [PATCH] add safe version of list_for_each_entry() to list.h
  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
  0 siblings, 2 replies; 11+ messages in thread
From: Christoph Hellwig @ 2002-10-04 13:58 UTC (permalink / raw)
  To: Kevin Corry; +Cc: Greg KH, Mark Peloquin, torvalds, linux-kernel, evms-devel

> =========================================================
> 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	Tue Oct  1 02:05:48 2002
> +++ linux-2.5.40b/include/linux/list.h	Thu Oct  3 19:17:27 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);

Wouldn't return (member->next && member->prev); be simpler?

> + */
> +#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..


^ 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 13:58     ` Christoph Hellwig
  2002-10-04 13:48       ` Kevin Corry
@ 2002-10-04 13:51       ` Kevin Corry
  1 sibling, 0 replies; 11+ messages in thread
From: Kevin Corry @ 2002-10-04 13:51 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: torvalds, linux-kernel, evms-devel

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 */
 

^ 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 13:58     ` Christoph Hellwig
@ 2002-10-04 13:48       ` Kevin Corry
  2002-10-04 13:51       ` Kevin Corry
  1 sibling, 0 replies; 11+ messages in thread
From: Kevin Corry @ 2002-10-04 13:48 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: Greg KH, Mark Peloquin, torvalds, linux-kernel, evms-devel

On Friday 04 October 2002 08:58, Christoph Hellwig wrote:
> > +/**
> > + * 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);
>
> Wouldn't return (member->next && member->prev); be simpler?

Sure. New patch below with new list_member() function.

> > + */
> > +#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..

Perhaps. But there are plenty of places in list.h that have some strange
indenting. If you'd like it another way, please post a patch with your
preferred version.

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


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

* Re: [PATCH] add safe version of list_for_each_entry() to list.h
  2002-10-03 23:44 ` Greg KH
@ 2002-10-04  0:25   ` Kevin Corry
  2002-10-04 13:58     ` Christoph Hellwig
  0 siblings, 1 reply; 11+ messages in thread
From: Kevin Corry @ 2002-10-04  0:25 UTC (permalink / raw)
  To: Greg KH, Mark Peloquin; +Cc: torvalds, linux-kernel, evms-devel

On Thursday 03 October 2002 18:44, Greg KH wrote:
> On Thu, Oct 03, 2002 at 06:42:09PM -0500, Mark Peloquin wrote:
> > Please consider adding the following patch to list.h.
>
> This patch had the tabs mangled and would not apply.
>
> Yeah, Notes sucks for sending patches...

It does indeed. Avoid Notes at all costs. :)

Here is the patch again. Should apply cleanly this time.

-Kevin

=========================================================
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	Tue Oct  1 02:05:48 2002
+++ linux-2.5.40b/include/linux/list.h	Thu Oct  3 19:17:27 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)
 {
@@ -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 */
 

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

* Re: [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
  2002-10-04  0:25   ` Kevin Corry
  0 siblings, 1 reply; 11+ messages in thread
From: Greg KH @ 2002-10-03 23:44 UTC (permalink / raw)
  To: Mark Peloquin; +Cc: torvalds, linux-kernel, evms-devel

On Thu, Oct 03, 2002 at 06:42:09PM -0500, Mark Peloquin wrote:
> Please consider adding the following patch to list.h.

This patch had the tabs mangled and would not apply.

Yeah, Notes sucks for sending patches...

thanks,

greg k-h

^ 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 15:48 [PATCH] add safe version of list_for_each_entry() to list.h Mark Peloquin
2002-10-04 16:00 ` Matthew Wilcox
2002-10-04 16:33   ` Andrew Morton
  -- strict thread matches above, loose matches on Subject: below --
2002-10-04 16:40 Mark Peloquin
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).