[lkml]   [2013]   [Jun]   [7]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
SubjectRe: [PATCH 1/2] list: add list_for_each_entry_del
On Fri, Jun 7, 2013 at 7:36 PM, Jörn Engel <> wrote:
> On Thu, 6 June 2013 22:49:22 +0300, Andy Shevchenko wrote:
>> On Thu, Jun 6, 2013 at 9:12 PM, Jörn Engel <> wrote:
>> > On Thu, 6 June 2013 22:32:55 +0300, Andy Shevchenko wrote:
>> >> 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

Who is doing such thing?

Usually if you unlock, you exit from function, or you already done
iteration through the list.

list_for_each_safe() {
if (condition) {

In case you have to do unlock()/lock() routine inside iteration you always can
do an additional check at the end

list_for_each_safe() {
if (!list_empty()) {

Thus, I don't see how list*del will help.

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

With Best Regards,
Andy Shevchenko
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to
More majordomo info at
Please read the FAQ at

 \ /
  Last update: 2013-06-07 21:21    [W:0.120 / U:0.860 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site