Skip to content

Commit

Permalink
memblock: use kfree() to release kmalloced memblock regions
Browse files Browse the repository at this point in the history
commit c94afc4 upstream.

memblock.{reserved,memory}.regions may be allocated using kmalloc() in
memblock_double_array(). Use kfree() to release these kmalloced regions
indicated by memblock_{reserved,memory}_in_slab.

Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
Fixes: 3010f87 ("mm: discard memblock data later")
Signed-off-by: Mike Rapoport <rppt@linux.ibm.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
MiaoheLin authored and gregkh committed Mar 2, 2022
1 parent 83f331d commit fd21a0b
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions mm/memblock.c
Expand Up @@ -366,14 +366,20 @@ void __init memblock_discard(void)
addr = __pa(memblock.reserved.regions);
size = PAGE_ALIGN(sizeof(struct memblock_region) *
memblock.reserved.max);
__memblock_free_late(addr, size);
if (memblock_reserved_in_slab)
kfree(memblock.reserved.regions);
else
__memblock_free_late(addr, size);
}

if (memblock.memory.regions != memblock_memory_init_regions) {
addr = __pa(memblock.memory.regions);
size = PAGE_ALIGN(sizeof(struct memblock_region) *
memblock.memory.max);
__memblock_free_late(addr, size);
if (memblock_memory_in_slab)
kfree(memblock.memory.regions);
else
__memblock_free_late(addr, size);
}

memblock_memory = NULL;
Expand Down

0 comments on commit fd21a0b

Please sign in to comment.