From: David Hildenbrand <da...@redhat.com>

[ Upstream commit 89c02e69fc5245f8a2f34b58b42d43a737af1a5e ]

Right now we are using find_memory_block() to get the node id for the
pfn range to online.  We are missing to drop a reference to the memory
block device.  While the device still gets unregistered via
device_unregister(), resulting in no user visible problem, the device is
never released via device_release(), resulting in a memory leak.  Fix
that by properly using a put_device().

Link: http://lkml.kernel.org/r/20190411110955.1430-1-da...@redhat.com
Fixes: d0dc12e86b31 ("mm/memory_hotplug: optimize memory hotplug")
Signed-off-by: David Hildenbrand <da...@redhat.com>
Reviewed-by: Oscar Salvador <osalva...@suse.de>
Reviewed-by: Wei Yang <richard.weiy...@gmail.com>
Acked-by: Michal Hocko <mho...@suse.com>
Acked-by: Pankaj Gupta <pagu...@redhat.com>
Cc: David Hildenbrand <da...@redhat.com>
Cc: Pavel Tatashin <pasha.tatas...@soleen.com>
Cc: Qian Cai <c...@lca.pw>
Cc: Arun KS <aru...@codeaurora.org>
Cc: Mathieu Malaterre <ma...@debian.org>
Signed-off-by: Andrew Morton <a...@linux-foundation.org>
Signed-off-by: Linus Torvalds <torva...@linux-foundation.org>
Signed-off-by: Sasha Levin <sas...@kernel.org>
---
 mm/memory_hotplug.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c
index 156991edec2a..af6735562215 100644
--- a/mm/memory_hotplug.c
+++ b/mm/memory_hotplug.c
@@ -901,6 +901,7 @@ int __ref online_pages(unsigned long pfn, unsigned long 
nr_pages, int online_typ
         */
        mem = find_memory_block(__pfn_to_section(pfn));
        nid = mem->nid;
+       put_device(&mem->dev);
 
        /* associate pfn range with the zone */
        zone = move_pfn_range(online_type, nid, pfn, nr_pages);
-- 
2.20.1

Reply via email to