lkml.org 
[lkml]   [2018]   [May]   [2]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH] mm: memory_hotplug: use put_device() if device_register fail
On Sat 28-04-18 11:05:44, arvindY wrote:
>
>
> On Friday 27 April 2018 08:26 PM, Michal Hocko wrote:
> > 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.?
> The document is correct. Here device_register() will initialize object by
> making reference count as 1 and also increment reference count for device.
>
> device_register() {
> device_initialize()->kobject_init()->kref_init() - initialize object(
> reference count = 1).
> device_add()->get_device() - increment reference count for device.
> }
>
> If device_register() will fail then we have to release the object by making
> reference count 0.

I am confused. If device_register intializes the reference to 1 then why
it doesn't decrement it on a failure path and rather expects the caller
to do that? The doc as I read it means that we should only drop a
reference if we have our own one before calling device_register.

Or what do I miss here?
--
Michal Hocko
SUSE Labs

\
 
 \ /
  Last update: 2018-05-02 16:28    [W:0.318 / U:0.056 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site