Skip to content

Commit

Permalink
include/linux/gfp.h: work around apparent sparse confusion
Browse files Browse the repository at this point in the history
Running sparse on page_alloc.c today, it errors out:
        include/linux/gfp.h:254:17: error: bad constant expression
        include/linux/gfp.h:254:17: error: cannot size expression

which is a line in gfp_zone():

        BUILD_BUG_ON((GFP_ZONE_BAD >> bit) & 1);

That's really unfortunate, because it ends up hiding all of the other
legitimate sparse messages like this:
        mm/page_alloc.c:5315:59: warning: incorrect type in argument 1 (different base types)
        mm/page_alloc.c:5315:59:    expected unsigned long [unsigned] [usertype] size
        mm/page_alloc.c:5315:59:    got restricted gfp_t [usertype] <noident>
...

Having sparse be able to catch these very oopsable bugs is a lot more
important than keeping a BUILD_BUG_ON().  Kill the BUILD_BUG_ON().

Compiles on x86_64 with and without CONFIG_DEBUG_VM=y.  defconfig boots
fine for me.

Signed-off-by: Dave Hansen <dave@linux.vnet.ibm.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
  • Loading branch information
Dave Hansen authored and Linus Torvalds committed May 25, 2011
1 parent 72788c3 commit 15fa8f4
Showing 1 changed file with 1 addition and 6 deletions.
7 changes: 1 addition & 6 deletions include/linux/gfp.h
Original file line number Diff line number Diff line change
Expand Up @@ -249,14 +249,9 @@ static inline enum zone_type gfp_zone(gfp_t flags)

z = (GFP_ZONE_TABLE >> (bit * ZONES_SHIFT)) &
((1 << ZONES_SHIFT) - 1);

if (__builtin_constant_p(bit))
BUILD_BUG_ON((GFP_ZONE_BAD >> bit) & 1);
else {
#ifdef CONFIG_DEBUG_VM
BUG_ON((GFP_ZONE_BAD >> bit) & 1);
BUG_ON((GFP_ZONE_BAD >> bit) & 1);
#endif
}
return z;
}

Expand Down

0 comments on commit 15fa8f4

Please sign in to comment.