LKML Archive on
help / color / mirror / Atom feed
From: Michal Hocko <>
To: arvindY <>
Subject: Re: [PATCH] mm: memory_hotplug: use put_device() if device_register fail
Date: Wed, 2 May 2018 16:27:41 +0200	[thread overview]
Message-ID: <> (raw)
In-Reply-To: <>

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

      reply	other threads:[~2018-05-02 14:27 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-26 15:42 [PATCH] mm: memory_hotplug: use put_device() if device_register fail Arvind Yadav
2018-04-27 14:56 ` Michal Hocko
2018-04-28  5:35   ` arvindY
2018-05-02 14:27     ` Michal Hocko [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \ \ \ \ \ \

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).