Skip to content

Commit

Permalink
memblock: memblock should be able to handle zero length operations
Browse files Browse the repository at this point in the history
Commit 24aa078 ("memblock, x86: Replace memblock_x86_reserve/
free_range() with generic ones") replaced x86 specific memblock
operations with the generic ones; unfortunately, it lost zero length
operation handling in the process making the kernel panic if somebody
tries to reserve zero length area.

There isn't much to be gained by being cranky to zero length operations
and panicking is almost the worst response.  Drop the BUG_ON() in
memblock_reserve() and update memblock_add_region/isolate_range() so
that all zero length operations are handled as noops.

Signed-off-by: Tejun Heo <[email protected]>
Cc: [email protected]
Reported-by: Valere Monseur <[email protected]>
Bisected-by: Joseph Freeman <[email protected]>
Tested-by: Joseph Freeman <[email protected]>
Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=43098
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
htejun authored and torvalds committed Apr 20, 2012
1 parent 310eb77 commit b3dc627
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion mm/memblock.c
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,9 @@ static int __init_memblock memblock_add_region(struct memblock_type *type,
phys_addr_t end = base + memblock_cap_size(base, &size);
int i, nr_new;

if (!size)
return 0;

/* special case for empty array */
if (type->regions[0].size == 0) {
WARN_ON(type->cnt != 1 || type->total_size);
Expand Down Expand Up @@ -430,6 +433,9 @@ static int __init_memblock memblock_isolate_range(struct memblock_type *type,

*start_rgn = *end_rgn = 0;

if (!size)
return 0;

/* we'll create at most two more regions */
while (type->cnt + 2 > type->max)
if (memblock_double_array(type) < 0)
Expand Down Expand Up @@ -514,7 +520,6 @@ int __init_memblock memblock_reserve(phys_addr_t base, phys_addr_t size)
(unsigned long long)base,
(unsigned long long)base + size,
(void *)_RET_IP_);
BUG_ON(0 == size);

return memblock_add_region(_rgn, base, size, MAX_NUMNODES);
}
Expand Down

0 comments on commit b3dc627

Please sign in to comment.