[PATCH 2/6] treewide: remove using list iterator after loop body as a ptr

Jeffrey Walton noloader at gmail.com
Tue Mar 1 08:18:56 AEDT 2022


On Mon, Feb 28, 2022 at 3:45 PM James Bottomley
<James.Bottomley at hansenpartnership.com> wrote:
> ...
> > Just from skimming over the patches to change this and experience
> > with the drivers/subsystems I help to maintain I think the primary
> > pattern looks something like this:
> >
> > list_for_each_entry(entry, head, member) {
> >      if (some_condition_checking(entry))
> >          break;
> > }
> > do_something_with(entry);
>
>
> Actually, we usually have a check to see if the loop found anything,
> but in that case it should something like
>
> if (list_entry_is_head(entry, head, member)) {
>     return with error;
> }
> do_somethin_with(entry);

Borrowing from c++, perhaps an explicit end should be used:

  if (list_entry_not_end(entry))
    do_somethin_with(entry)

It is modelled after c++ and the 'while(begin != end) {}' pattern.

Jeff


More information about the Linuxppc-dev mailing list