lkml.org 
[lkml]   [2021]   [Aug]   [26]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
SubjectRE: [PATCH] PCI: hv: Fix a bug on removing child devices on the bus
Date
From: Long Li <longli@microsoft.com> Sent: Wednesday, August 25, 2021 1:25 PM

> >
> > I thought list_for_each_entry_safe() is for use when list manipulation is *not*
> > protected by a lock and you want to safely walk the list even if an entry gets
> > removed. If the list is protected by a lock or not subject to contention (as is the
> > case here), then
> > list_for_each_entry() is the simpler implementation. The original
> > implementation didn't need to use the _safe version because of the spin lock.
> >
> > Or do I have it backwards?
> >
> > Michael
>
> I think we need list_for_each_entry_safe() because we delete the list elements while going through them:
>
> Here is the comment on list_for_each_entry_safe():
> /**
> * Loop through the list, keeping a backup pointer to the element. This
> * macro allows for the deletion of a list element while looping through the
> * list.
> *
> * See list_for_each_entry for more details.
> */
>

Got it. Thanks (and to Rob Herring). I read that comment but
with the wrong assumptions and didn't understand it correctly.

Interestingly, pci-hyperv.c has another case of looping through
this list and removing items where the _safe version is not used.
See pci_devices_present_work() where the missing children are
moved to a list on the stack.

Michael
\
 
 \ /
  Last update: 2021-08-26 18:51    [W:0.070 / U:0.164 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site