diff mbox series

memblock: use kfree() to release kmalloced memblock regions

Message ID 20220217145327.16553-1-linmiaohe@huawei.com (mailing list archive)
State New
Headers show
Series memblock: use kfree() to release kmalloced memblock regions | expand

Commit Message

Miaohe Lin Feb. 17, 2022, 2:53 p.m. UTC
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: 3010f876500f ("mm: discard memblock data later")
---
 mm/memblock.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

Comments

Mike Rapoport Feb. 17, 2022, 9:53 p.m. UTC | #1
From: Mike Rapoport <rppt@linux.ibm.com>

On Thu, 17 Feb 2022 22:53:27 +0800, Miaohe Lin wrote:
> 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.
> 
> 

Applied, thanks!

[1/1] memblock: use kfree() to release kmalloced memblock regions
      (no commit info)

Best regards,
diff mbox series

Patch

diff --git a/mm/memblock.c b/mm/memblock.c
index 11561bbff8f5..e4f03a6e8e56 100644
--- a/mm/memblock.c
+++ b/mm/memblock.c
@@ -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;