Re: [PATCH] fix sparse warning from include/linux/mmzone.h

From: Harvey Harrison
Date: Fri Feb 08 2008 - 17:18:26 EST


On Fri, 2008-02-08 at 14:04 -0800, Linus Torvalds wrote:
>
> On Fri, 8 Feb 2008, Andrew Morton wrote:
> > > #ifdef CONFIG_HIGHMEM
> > > - int zone_idx = zone - zone->zone_pgdat->node_zones;
> > > - return zone_idx == ZONE_HIGHMEM ||
> > > - (zone_idx == ZONE_MOVABLE && zone_movable_is_highmem());
> > > + const int highmem_off = ZONE_HIGHMEM * sizeof(*zone);
> > > + const int movable_off = ZONE_MOVABLE * sizeof(*zone);
> > > +
> > > + int zone_off = (unsigned long)zone - (unsigned long)zone->zone_pgdat->node_zones;
> > > + return zone_off == highmem_off ||
> > > + (zone_off == movable_off && zone_movable_is_highmem());
> >
> > hrm. For my i386 build (and that's where CONFIG_HIGHMEM really matters)
> > this patch makes mm/page_alloc.o six bytes larger, and I don't think the
> > change did much for readability.
>
> Heh, yeah. That's a very odd way to write it.

As long as you read 'odd' as 'rather dumb'

>
> It would probably make more sense to just write it as something like
>
> struct zone *base = zone->zone_pgdat->node_zones;
>
> if (zone == base + ZONE_HIGHMEM ||
> (zone == base + ZONE_MOVABLE && zone_movable_is_highmem());

s/if/return/ I think. And missing a closing brace. Unless I'm (again)
missing something.

Harvey


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/