All of lore.kernel.org
 help / color / mirror / Atom feed
From: Masami Hiramatsu <mhiramat@redhat.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: ananth@in.ibm.com, jkenisto@us.ibm.com,
	linux-kernel@vger.kernel.org, systemtap@sources.redhat.com,
	prasanna@in.ibm.com, shaohua.li@intel.com, davem@davemloft.net,
	fche@redhat.com
Subject: Re: [PATCH -mm 1/5] list.h: add list_singleton
Date: Fri, 14 Mar 2008 18:22:26 -0400	[thread overview]
Message-ID: <47DAFAA2.20302@redhat.com> (raw)
In-Reply-To: <20080314140007.a7b495d7.akpm@linux-foundation.org>

Andrew Morton wrote:
> 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.

I agreed. I assume that list_singleton() is used like as list_empty().


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

Thank you,

-- 
Masami Hiramatsu

Software Engineer
Hitachi Computer Products (America) Inc.
Software Solutions Division

e-mail: mhiramat@redhat.com


  reply	other threads:[~2008-03-14 22:23 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-03-14 20:40 [PATCH -mm 1/5] list.h: add list_singleton Masami Hiramatsu
2008-03-14 21:00 ` Andrew Morton
2008-03-14 22:22   ` Masami Hiramatsu [this message]
2008-03-15 22:36     ` Peter Zijlstra
2008-03-17 15:04       ` Masami Hiramatsu
2008-03-17 15:13         ` Peter Zijlstra
2008-03-17 20:52           ` [PATCH -mm] list.h: rename list_singleton to list_is_singular Masami Hiramatsu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=47DAFAA2.20302@redhat.com \
    --to=mhiramat@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=ananth@in.ibm.com \
    --cc=davem@davemloft.net \
    --cc=fche@redhat.com \
    --cc=jkenisto@us.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=prasanna@in.ibm.com \
    --cc=shaohua.li@intel.com \
    --cc=systemtap@sources.redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.