diff options
author | Arvind Yadav <arvind.yadav.cs@gmail.com> | 2018-04-26 21:12:09 +0530 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2018-05-14 16:48:59 +0200 |
commit | 085aa2de568493d7cde52126512d37260077811a (patch) | |
tree | 22235cd9fcfa90729a66da2c7538cec0f0d56ba7 /drivers | |
parent | 13509860efcada3e57c16d5f2e60dda8cef6054c (diff) | |
download | linux-085aa2de568493d7cde52126512d37260077811a.tar.bz2 |
mm: memory_hotplug: use put_device() if device_register fail
if device_register() returned an error. Always use put_device()
to give up the initialized reference and release allocated memory.
Signed-off-by: Arvind Yadav <arvind.yadav.cs@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/base/memory.c | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/drivers/base/memory.c b/drivers/base/memory.c index bffe8616bd55..f5e560188a18 100644 --- a/drivers/base/memory.c +++ b/drivers/base/memory.c @@ -649,13 +649,19 @@ static const struct attribute_group *memory_memblk_attr_groups[] = { static int register_memory(struct memory_block *memory) { + int ret; + memory->dev.bus = &memory_subsys; memory->dev.id = memory->start_section_nr / sections_per_block; memory->dev.release = memory_block_release; memory->dev.groups = memory_memblk_attr_groups; memory->dev.offline = memory->state == MEM_OFFLINE; - return device_register(&memory->dev); + ret = device_register(&memory->dev); + if (ret) + put_device(&memory->dev); + + return ret; } static int init_memory_block(struct memory_block **memory, |