From: "Jörn Engel" <joern@logfs.org>
To: Andy Shevchenko <andy.shevchenko@gmail.com>
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
Chris Mason <chris.mason@fusionio.com>,
linux-btrfs@vger.kernel.org
Subject: Re: [PATCH 1/2] list: add list_for_each_entry_del
Date: Fri, 7 Jun 2013 12:36:58 -0400 [thread overview]
Message-ID: <20130607163658.GC25323@logfs.org> (raw)
In-Reply-To: <CAHp75VfFvirRvN8FwNey4=9GvMKmPvaM5PBThbEBwZYwL_pt-A@mail.gmail.com>
On Thu, 6 June 2013 22:49:22 +0300, Andy Shevchenko wrote:
> On Thu, Jun 6, 2013 at 9:12 PM, Jörn Engel <joern@logfs.org> wrote:
> > On Thu, 6 June 2013 22:32:55 +0300, Andy Shevchenko wrote:
> >> On Mon, Jun 3, 2013 at 8:28 PM, Joern Engel <joern@logfs.org> wrote:
> >> > I have seen a lot of boilerplate code that either follows the pattern of
> >> > while (!list_empty(head)) {
> >> > pos = list_entry(head->next, struct foo, list);
> >> > list_del(pos->list);
> >> > ...
> >> > }
> >> > or some variant thereof.
> >>
> >> What the problem to use list_for_each_safe()?
> >
> > The loop may terminate with elements left on the list. There is more,
> > but I would consider this the main problem.
>
> I didn't quite get what you mean.
Take two threads, one doing a list_for_each_entry_safe loop and
dropping the lock after list_del, the other doing list_add. Result is
that you finish the list_for_each_entry_safe loop with something
remaining on the list.
spin_lock
list_for_each_entry_safe
list_del
spin_unlock
spin_lock
list_add
spin_unlock
If you search for this pattern in the kernel, you won't find too many
examples. Quite likely that is because a) people realized this and
used a while (!list_empty()) loop to begin with or b) they started out
wrong and fixed the bug later. Not sure how many examples of b) there
are.
At any rate, this is a purely janitorial patch. It is almost by
definition of moderate utility and if there is significant opposition
or the patch actually causes harm in some way, we should drop it.
Jörn
--
Time? What's that? Time is only worth what you do with it.
-- Theo de Raadt
next prev parent reply other threads:[~2013-06-07 18:06 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-06-03 17:28 [PATCH 0/2] introduce list_for_each_entry_del Joern Engel
2013-06-03 17:28 ` [PATCH 1/2] list: add list_for_each_entry_del Joern Engel
2013-06-06 19:32 ` Andy Shevchenko
2013-06-06 18:12 ` Jörn Engel
2013-06-06 19:49 ` Andy Shevchenko
2013-06-07 16:36 ` Jörn Engel [this message]
2013-06-07 18:30 ` Andy Shevchenko
2013-06-07 18:48 ` Jörn Engel
2013-06-08 0:03 ` Andy Shevchenko
2013-06-03 17:28 ` [PATCH 2/2] btrfs: use list_for_each_entry_del Joern Engel
2013-06-03 18:07 ` [PATCH 0/2] introduce list_for_each_entry_del Jörn Engel
2013-06-03 20:49 ` Christoph Hellwig
2013-06-03 19:36 ` Jörn Engel
2013-06-03 19:55 ` Jörn Engel
2013-06-04 14:48 ` Christoph Hellwig
2013-06-04 14:53 ` Chris Mason
2013-06-04 20:09 ` Arne Jansen
2013-06-04 18:44 ` Jörn Engel
2013-06-05 2:03 ` [PATCH 1/2] list: add while_list_drain_entry Jörn Engel
2013-06-05 14:32 ` David Sterba
2013-06-05 2:04 ` [PATCH 2/2] btrfs: use while_list_drain_entry Jörn Engel
2013-06-05 2:09 ` [PATCH 0/2] introduce list_for_each_entry_del Jörn Engel
2013-06-05 6:53 ` Arne Jansen
2013-06-05 14:25 ` David Sterba
2013-07-05 20:41 ` Jörn Engel
2013-07-05 20:41 ` [PATCH 1/2] list: add list_del_each_entry Jörn Engel
2013-07-05 22:38 ` Filipe David Manana
2013-07-15 17:35 ` Jörn Engel
2013-07-05 20:41 ` [PATCH 2/2] btrfs: use list_del_each_entry Jörn Engel
2013-07-08 4:37 ` [PATCH 0/2] introduce list_for_each_entry_del Dave Chinner
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=20130607163658.GC25323@logfs.org \
--to=joern@logfs.org \
--cc=andy.shevchenko@gmail.com \
--cc=chris.mason@fusionio.com \
--cc=linux-btrfs@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/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 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).