From 84a0d243b608b3373ef701c20a64353269d69e46 Mon Sep 17 00:00:00 2001 From: Patrick Daly Date: Mon, 22 Aug 2022 18:00:51 -0700 Subject: [PATCH] ANDROID: mm/memory_hotplug: Fix error path handling Correct a resource leak if arch_add_memory() returns failure. Bug: 243477359 Change-Id: I1dce82a18c2242d7b6fd9fb1fe3a8b2ba67853de Fixes: 417ac617ea5e ("ANDROID: mm/memory_hotplug: implement {add/remove}_memory_subsection") Signed-off-by: Patrick Daly Signed-off-by: Chris Goldsworthy --- mm/memory_hotplug.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index 6702c1114ced..9176bae95c9a 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -1156,14 +1156,22 @@ int add_memory_subsection(int nid, u64 start, u64 size) ret = arch_add_memory(nid, start, size, ¶ms); if (ret) { - if (IS_ENABLED(CONFIG_ARCH_KEEP_MEMBLOCK)) - memblock_remove(start, size); pr_err("%s failed to add subsection start 0x%llx size 0x%llx\n", __func__, start, size); + goto err_add_memory; } mem_hotplug_done(); return ret; + +err_add_memory: + if (IS_ENABLED(CONFIG_ARCH_KEEP_MEMBLOCK)) + memblock_remove(start, size); + + mem_hotplug_done(); + + release_memory_resource(res); + return ret; } EXPORT_SYMBOL_GPL(add_memory_subsection);