memblock: fix returned memory region overrunning reserved memory region
This commit is contained in:
@@ -235,8 +235,8 @@ static phys_addr_t do_alloc(size_t size, phys_addr_t align)
|
|||||||
align = 0x8;
|
align = 0x8;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* the base address of the memory region to reserved */
|
/* the bounds of the memory region to reserve */
|
||||||
phys_addr_t allocated_base = ADDR_MAX;
|
phys_addr_t allocated_base = ADDR_MAX, allocated_limit = 0;
|
||||||
/* the address to return to the caller. may be different from
|
/* the address to return to the caller. may be different from
|
||||||
allocated_base depending on alignment requirements. */
|
allocated_base depending on alignment requirements. */
|
||||||
phys_addr_t returned_base = ADDR_MAX;
|
phys_addr_t returned_base = ADDR_MAX;
|
||||||
@@ -255,6 +255,7 @@ static phys_addr_t do_alloc(size_t size, phys_addr_t align)
|
|||||||
size_t region_size = it.it_limit - base + 1;
|
size_t region_size = it.it_limit - base + 1;
|
||||||
if (region_size >= size) {
|
if (region_size >= size) {
|
||||||
allocated_base = it.it_base;
|
allocated_base = it.it_base;
|
||||||
|
allocated_limit = base + size;
|
||||||
returned_base = base;
|
returned_base = base;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -264,7 +265,7 @@ static phys_addr_t do_alloc(size_t size, phys_addr_t align)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int status = memblock_add_range(&memblock.reserved, allocated_base, size, MEMBLOCK_ALLOC);
|
int status = memblock_add_range(&memblock.reserved, allocated_base, allocated_limit - allocated_base, MEMBLOCK_ALLOC);
|
||||||
if (status != 0) {
|
if (status != 0) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user