aboutsummaryrefslogtreecommitdiffstats
path: root/lib/lmb.c
diff options
context:
space:
mode:
authorDavid S. Miller <davem@davemloft.net>2008-02-13 19:57:09 -0500
committerDavid S. Miller <davem@davemloft.net>2008-02-13 19:57:09 -0500
commiteea89e13a9c61d3928223d2f9bf2295e22e0efb6 (patch)
treef6b2cc514071d276a287eb666333667b6ee67c4f /lib/lmb.c
parentd9b2b2a277219d4812311d995054ce4f95067725 (diff)
[LMB]: Fix bug in __lmb_alloc_base().
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>
Diffstat (limited to 'lib/lmb.c')
-rw-r--r--lib/lmb.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/lib/lmb.c b/lib/lmb.c
index 98078b4ec20e..6390d63a2a0e 100644
--- a/lib/lmb.c
+++ b/lib/lmb.c
@@ -245,6 +245,11 @@ static unsigned long lmb_align_down(unsigned long addr, unsigned long size)
245 return addr & ~(size - 1); 245 return addr & ~(size - 1);
246} 246}
247 247
248static unsigned long lmb_align_up(unsigned long addr, unsigned long size)
249{
250 return (addr + (size - 1)) & ~(size - 1);
251}
252
248unsigned long __init __lmb_alloc_base(unsigned long size, unsigned long align, 253unsigned long __init __lmb_alloc_base(unsigned long size, unsigned long align,
249 unsigned long max_addr) 254 unsigned long max_addr)
250{ 255{
@@ -281,7 +286,8 @@ unsigned long __init __lmb_alloc_base(unsigned long size, unsigned long align,
281 if (i < 0) 286 if (i < 0)
282 return 0; 287 return 0;
283 288
284 lmb_add_region(&lmb.reserved, base, size); 289 if (lmb_add_region(&lmb.reserved, base, lmb_align_up(size, align)) < 0)
290 return 0;
285 291
286 return base; 292 return base;
287} 293}