Commit 7ea0d2d7 authored by David Hildenbrand's avatar David Hildenbrand Committed by Linus Torvalds

drivers/base/memory: add memory block to memory group after registration succeeded

If register_memory() fails, we freed the memory block but already added
the memory block to the group list, not good.  Let's defer adding the
block to the memory group to after registering the memory block device.

We do handle it properly during unregister_memory(), but that's not
called when the registration fails.

Link: https://lkml.kernel.org/r/20220128144540.153902-1-david@redhat.com
Fixes: 028fc57a ("drivers/base/memory: introduce "memory groups" to logically group memory blocks")
Signed-off-by: default avatarDavid Hildenbrand <david@redhat.com>
Reviewed-by: default avatarOscar Salvador <osalvador@suse.de>
Acked-by: default avatarMichal Hocko <mhocko@suse.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: "Rafael J. Wysocki" <rafael@kernel.org>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 8c9bb398
...@@ -665,14 +665,16 @@ static int init_memory_block(unsigned long block_id, unsigned long state, ...@@ -665,14 +665,16 @@ static int init_memory_block(unsigned long block_id, unsigned long state,
mem->nr_vmemmap_pages = nr_vmemmap_pages; mem->nr_vmemmap_pages = nr_vmemmap_pages;
INIT_LIST_HEAD(&mem->group_next); INIT_LIST_HEAD(&mem->group_next);
ret = register_memory(mem);
if (ret)
return ret;
if (group) { if (group) {
mem->group = group; mem->group = group;
list_add(&mem->group_next, &group->memory_blocks); list_add(&mem->group_next, &group->memory_blocks);
} }
ret = register_memory(mem); return 0;
return ret;
} }
static int add_memory_block(unsigned long base_section_nr) static int add_memory_block(unsigned long base_section_nr)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment