Skip to content

Commit

Permalink
mm: make vb_alloc() more foolproof
Browse files Browse the repository at this point in the history
If someone calls vb_alloc() (or vm_map_ram() for that matter) to allocate
0 bytes (0 pages), get_order() returns BITS_PER_LONG - PAGE_CACHE_SHIFT
and interesting stuff happens.  So make debugging such problems easier and
warn about 0-size allocation.

[[email protected]: use WARN_ON-return-value feature]
Signed-off-by: Jan Kara <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
jankara authored and torvalds committed Aug 1, 2012
1 parent 92ca922 commit aa91c4d
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions mm/vmalloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -904,6 +904,14 @@ static void *vb_alloc(unsigned long size, gfp_t gfp_mask)

BUG_ON(size & ~PAGE_MASK);
BUG_ON(size > PAGE_SIZE*VMAP_MAX_ALLOC);
if (WARN_ON(size == 0)) {
/*
* Allocating 0 bytes isn't what caller wants since
* get_order(0) returns funny result. Just warn and terminate
* early.
*/
return NULL;
}
order = get_order(size);

again:
Expand Down

0 comments on commit aa91c4d

Please sign in to comment.