On Thu 26-04-18 21:12:09, Arvind Yadav wrote: > if device_register() returned an error. Always use put_device() > to give up the initialized reference and release allocated memory.
Is this patch correct? The docummentation says * NOTE: _Never_ directly free @dev after calling this function, even * if it returned an error! Always use put_device() to give up your * reference instead. but we do not have _our_ reference in this path AFAICS. Maybe this is just a documentation issue? How have you tested this change btw.? > Signed-off-by: Arvind Yadav <arvind.yadav...@gmail.com> > --- > drivers/base/memory.c | 8 +++++++- > 1 file changed, 7 insertions(+), 1 deletion(-) > > diff --git a/drivers/base/memory.c b/drivers/base/memory.c > index bffe861..f5e5601 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, > -- > 2.7.4 -- Michal Hocko SUSE Labs