Skip to content

Commit

Permalink
mm: memory_hotplug: use put_device() if device_register fail
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
ArvindYadavCs authored and gregkh committed May 14, 2018
1 parent 1350986 commit 085aa2d
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion drivers/base/memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 085aa2d

Please sign in to comment.