Skip to content

Commit

Permalink
[LMB]: Fix bug in __lmb_alloc_base().
Browse files Browse the repository at this point in the history
We need to check lmb_add_region() for errors, it can run out
of regions etc.

Also, the size needs to be padded to the given alignment
or else the lmb.reserved regions don't get expanded and
instead we get tons of holes and eventually run out of
regions prematurely.

Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
davem330 committed Feb 14, 2008
1 parent d9b2b2a commit eea89e1
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/lmb.c
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,11 @@ static unsigned long lmb_align_down(unsigned long addr, unsigned long size)
return addr & ~(size - 1);
}

static unsigned long lmb_align_up(unsigned long addr, unsigned long size)
{
return (addr + (size - 1)) & ~(size - 1);
}

unsigned long __init __lmb_alloc_base(unsigned long size, unsigned long align,
unsigned long max_addr)
{
Expand Down Expand Up @@ -281,7 +286,8 @@ unsigned long __init __lmb_alloc_base(unsigned long size, unsigned long align,
if (i < 0)
return 0;

lmb_add_region(&lmb.reserved, base, size);
if (lmb_add_region(&lmb.reserved, base, lmb_align_up(size, align)) < 0)
return 0;

return base;
}
Expand Down

0 comments on commit eea89e1

Please sign in to comment.