2022-02-28 21:27:52

by Jeffrey Walton

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

On Mon, Feb 28, 2022 at 3:45 PM James Bottomley
<[email protected]> 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