aboutsummaryrefslogtreecommitdiffstats
path: root/mm
diff options
authorMuchun Song <songmuchun@bytedance.com>2026-05-11 16:43:07 +0800
committerAndrew Morton <akpm@linux-foundation.org>2026-05-28 21:30:55 -0700
commit917288900148b4fc2fdc5d2d8606f99508f4aabf (patch)
tree93b452af33ec3c20c89491cdf1bbf13e80ff1c25 /mm
parent29ff2eeda6cea60c1ea7a71e452f65513202b8eb (diff)
downloadlinux-next-history-917288900148b4fc2fdc5d2d8606f99508f4aabf.tar.gz
mm/memory_hotplug: factor out altmap freeing checks
Use a small helper to centralize altmap freeing after verifying that all vmemmap pages were released. This keeps the check consistent between the normal teardown path and the memory hotplug error paths. Link: https://lore.kernel.org/20260511084307.1827127-1-songmuchun@bytedance.com Signed-off-by: Muchun Song <songmuchun@bytedance.com> Suggested-by: David Hildenbrand (Arm) <david@kernel.org> Acked-by: David Hildenbrand (Arm) <david@kernel.org> Acked-by: Oscar Salvador <osalvador@suse.de> Reviewed-by: Donet Tom <donettom@linux.ibm.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Diffstat (limited to 'mm')
-rw-r--r--mm/memory_hotplug.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c
index 462d8dcd636dc..af5489f03771b 100644
--- a/mm/memory_hotplug.c
+++ b/mm/memory_hotplug.c
@@ -1403,6 +1403,12 @@ bool mhp_supports_memmap_on_memory(void)
}
EXPORT_SYMBOL_GPL(mhp_supports_memmap_on_memory);
+static void altmap_free(struct vmem_altmap *altmap)
+{
+ WARN_ONCE(altmap->alloc, "Altmap not fully unmapped");
+ kfree(altmap);
+}
+
static void remove_memory_blocks_and_altmaps(u64 start, u64 size)
{
unsigned long memblock_size = memory_block_size_bytes();
@@ -1427,12 +1433,8 @@ static void remove_memory_blocks_and_altmaps(u64 start, u64 size)
put_device(&mem->dev);
remove_memory_block_devices(cur_start, memblock_size);
-
arch_remove_memory(cur_start, memblock_size, altmap, NULL);
-
- /* Verify that all vmemmap pages have actually been freed. */
- WARN(altmap->alloc, "Altmap not fully unmapped");
- kfree(altmap);
+ altmap_free(altmap);
}
}
@@ -1463,7 +1465,7 @@ static int create_altmaps_and_memory_blocks(int nid, struct memory_group *group,
/* call arch's memory hotadd */
ret = arch_add_memory(nid, cur_start, memblock_size, &params);
if (ret < 0) {
- kfree(params.altmap);
+ altmap_free(params.altmap);
goto out;
}
@@ -1472,7 +1474,7 @@ static int create_altmaps_and_memory_blocks(int nid, struct memory_group *group,
params.altmap, group);
if (ret) {
arch_remove_memory(cur_start, memblock_size, params.altmap, NULL);
- kfree(params.altmap);
+ altmap_free(params.altmap);
goto out;
}
}