Re: [PATCH -mm 1/5] list.h: add list_singleton

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Andrew Morton
Date: Friday, March 14, 2008 - 2:00 pm

On Fri, 14 Mar 2008 16:40:36 -0400
Masami Hiramatsu <mhiramat@redhat.com> wrote:


This hurts my brain.

If your usage pattern is:

struct foo {
	...
	struct list_head bar_list;	/* A list of `struct bar's */
};

struct bar {
	struct list_head list;		/* Attached to foo.bar_list */
	...
};

then yes, list_singleton() makes sense.

But in other usage patterns it does not:

struct foo {
	struct bar *bar_list;
	...
};

struct bar {
	struct list_head list;		/* All the other bars go here */
	...
};

In the second case, emptiness is signified by foo.bar_list==NULL.  And in
this case, code which does

	if (foo->bar_list && list_singleton(&foo->bar_list->list))

will fail if there is a single item on the list!

The second usage pattern is uncommon and list_empty() also returns
misleading answers when list_heads are used this way.

So I guess we can proceed with your list_singleton(), but I'd just like to
flag this possible confusion, see what people think..

--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH -mm 1/5] list.h: add list_singleton, Masami Hiramatsu, (Fri Mar 14, 1:40 pm)
Re: [PATCH -mm 1/5] list.h: add list_singleton, Andrew Morton, (Fri Mar 14, 2:00 pm)
Re: [PATCH -mm 1/5] list.h: add list_singleton, Masami Hiramatsu, (Fri Mar 14, 3:22 pm)
Re: [PATCH -mm 1/5] list.h: add list_singleton, Peter Zijlstra, (Sat Mar 15, 3:36 pm)
Re: [PATCH -mm 1/5] list.h: add list_singleton, Masami Hiramatsu, (Mon Mar 17, 8:04 am)
Re: [PATCH -mm 1/5] list.h: add list_singleton, Peter Zijlstra, (Mon Mar 17, 8:13 am)
[PATCH -mm] list.h: rename list_singleton to list_is_singular, Masami Hiramatsu, (Mon Mar 17, 1:52 pm)