Skip to content

Commit 4978db5

Browse files
committed
lmb: Fix inconsistent alignment of size argument.
When allocating, if we will align up the size when making the reservation, we should also align the size for the check that the space is actually available. The simplest thing is to just aling the size up from the beginning, then we can use plain 'size' throughout. Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 94d149c commit 4978db5

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

lib/lmb.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -286,8 +286,7 @@ static u64 __init lmb_alloc_nid_unreserved(u64 start, u64 end,
286286
j = lmb_overlaps_region(&lmb.reserved, base, size);
287287
if (j < 0) {
288288
/* this area isn't reserved, take it */
289-
if (lmb_add_region(&lmb.reserved, base,
290-
lmb_align_up(size, align)) < 0)
289+
if (lmb_add_region(&lmb.reserved, base, size) < 0)
291290
base = ~(u64)0;
292291
return base;
293292
}
@@ -333,6 +332,10 @@ u64 __init lmb_alloc_nid(u64 size, u64 align, int nid,
333332
struct lmb_region *mem = &lmb.memory;
334333
int i;
335334

335+
BUG_ON(0 == size);
336+
337+
size = lmb_align_up(size, align);
338+
336339
for (i = 0; i < mem->cnt; i++) {
337340
u64 ret = lmb_alloc_nid_region(&mem->region[i],
338341
nid_range,
@@ -370,6 +373,8 @@ u64 __init __lmb_alloc_base(u64 size, u64 align, u64 max_addr)
370373

371374
BUG_ON(0 == size);
372375

376+
size = lmb_align_up(size, align);
377+
373378
/* On some platforms, make sure we allocate lowmem */
374379
/* Note that LMB_REAL_LIMIT may be LMB_ALLOC_ANYWHERE */
375380
if (max_addr == LMB_ALLOC_ANYWHERE)
@@ -393,8 +398,7 @@ u64 __init __lmb_alloc_base(u64 size, u64 align, u64 max_addr)
393398
j = lmb_overlaps_region(&lmb.reserved, base, size);
394399
if (j < 0) {
395400
/* this area isn't reserved, take it */
396-
if (lmb_add_region(&lmb.reserved, base,
397-
lmb_align_up(size, align)) < 0)
401+
if (lmb_add_region(&lmb.reserved, base, size) < 0)
398402
return 0;
399403
return base;
400404
}

0 commit comments

Comments
 (0)