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

Jeffrey Walton
2022-02-28T21:19:11Z

On Mon, Feb 28, 2022 at 3:45 PM James Bottomley
<James.Bottomley@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