From 083dd7168bef74ee8edf6d357e7edd7058fe5cea Mon Sep 17 00:00:00 2001 From: Jiacheng Zheng Date: Tue, 7 Jul 2020 19:18:05 +0800 Subject: [PATCH] mm/memblock.c: fix bug in early_dyn_memhotplug memblock.memory.cnt will decrease if we remove all memory blocks in a region. We will lose the next region in this condition. The solution is we save memblock.memory.cnt before we scan through a region and compare the new counter with the old one after that, we decrease the idx if we find counter changes. This way, we are always using the correct idx before we enter next loop. Change-Id: Id6bf83497f1048cf614e50e23484f2dea7ffcd07 Signed-off-by: Jiacheng Zheng --- mm/memblock.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/mm/memblock.c b/mm/memblock.c index deaf4c018e1e..dc202c7702c8 100644 --- a/mm/memblock.c +++ b/mm/memblock.c @@ -1833,12 +1833,14 @@ static bool __init memblock_in_no_hotplug_area(phys_addr_t addr) static int __init early_dyn_memhotplug(char *p) { - int idx = 0; + unsigned long idx = 0; + unsigned long old_cnt; phys_addr_t addr, rgn_end; struct memblock_region *rgn; int blk = 0; while (idx < memblock.memory.cnt) { + old_cnt = memblock.memory.cnt; rgn = &memblock.memory.regions[idx++]; addr = ALIGN(rgn->base, MIN_MEMORY_BLOCK_SIZE); rgn_end = rgn->base + rgn->size; @@ -1849,6 +1851,8 @@ static int __init early_dyn_memhotplug(char *p) } addr += MIN_MEMORY_BLOCK_SIZE; } + if (old_cnt != memblock.memory.cnt) + idx--; } return 0; }