Re: [PATCH] drivers/block/ub.c: use list_for_each_entry()

Pete Zaitcev
2007-05-30T23:08:32Z

On Thu, 31 May 2007 02:44:17 +0530, "Satyam Sharma" <satyam.sharma@gmail.com> wrote:

> > > - list_for_each(p, &sc->luns) {
> > > - lun = list_entry(p, struct ub_lun, link);
> > > + list_for_each_entry(lun, &sc->luns, link) {

> > This patch straddles the border of acceptable. The pointless obfuscation
> > is balanced against the removal of explicit type in list_entry() and thus
> > a possible mismatched struct. I'm not acking nor naking this.
>
> A list_for_each() followed by list_entry() ---> list_for_each_entry()
> conversion is a pretty harmless (and desirable) conversion, IMO.
> In fact list_for_each_entry() itself uses list_entry(..., typeof(*p), ...)
> which seems to be a safer way to use list_entry() than specifying
> the type explicity/manually in its arguments, no?

I believe I have mentioned the type safety as a positive, and in fact
it's quoted above. I just didn't think it necessary to use quite as
many words explaining it until now.

The negative is the sheer number of helper functions in list.h. Personally,
I find it difficult to retain a working knowledge of them. Iterators are
particularly nasty that way. I'm thinking about dropping all of these
list_for_each_with_murky_argument_requirements_and_odd_side_effects()
and use plain for(;;), as a courtesy to someone who has to read the
code years down the road.

-- Pete