mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: "Tobin C. Harding" <me@tobin.cc>
Cc: "Rafael J. Wysocki" <rafael@kernel.org>,
	cl@linux.com, tycho@tycho.ws, willy@infradead.org,
	linux-kernel@vger.kernel.org
Subject: Re: memleak around kobject_init_and_add()
Date: Sun, 28 Apr 2019 18:14:58 +0200	[thread overview]
Message-ID: <20190428161458.GB13309@kroah.com> (raw)
In-Reply-To: <20190428011957.GA18843@eros.localdomain>

On Sun, Apr 28, 2019 at 11:19:57AM +1000, Tobin C. Harding wrote:
> On Sat, Apr 27, 2019 at 09:28:09PM +0200, Greg Kroah-Hartman wrote:
> > On Sat, Apr 27, 2019 at 06:13:30PM +1000, Tobin C. Harding wrote:
> > > (Note at bottom on reasons for 'To' list 'Cc' list)
> > > 
> > > Hi,
> > > 
> > > kobject_init_and_add() seems to be routinely misused.  A failed call to this
> > > function requires a call to kobject_put() otherwise we leak memory.
> > > 
> > > Examples memleaks can be seen in:
> > > 
> > > 	mm/slub.c
> > > 	fs/btrfs/sysfs.c
> > > 	fs/xfs/xfs_sysfs.h: xfs_sysfs_init()
> > > 
> > >  Question: Do we fix the misuse or fix the API?
> > 
> > Fix the misuse.
> 
> Following on from this.  It seems we often also forget to call
> kobject_uevent() after calls to kobject_init_and_add().

Are you sure?  Usually if you don't call it right away, it happens much
later when you have everything "ready to go" to tell userspace that it
then can access that kobject successfully.

Any specific places you feel is not correct?

> Before I make a goose of myself patching the whole tree is there ever
> any reason why we would _not_ want to call kobject_uevent() after
> successfully calling kobject_add() (or kobject_init_and_add())?

You should always do so, but again, sometimes it can be much "later"
after everything is properly set up.

Ok, at quick glance I see some places that do not properly call this.
But, those places should not even be using a "raw" kobject in the first
place, they should be using 'struct device'.  If code using a kobject,
that should be very "rare", and not normal behavior in the first place.

thanks,

greg k-h

  reply	other threads:[~2019-04-28 16:15 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-27  8:13 Tobin C. Harding
2019-04-27 19:28 ` Greg Kroah-Hartman
2019-04-27 23:33   ` Tobin C. Harding
2019-04-28  1:19   ` Tobin C. Harding
2019-04-28 16:14     ` Greg Kroah-Hartman [this message]
2019-04-28 22:46       ` Tobin C. Harding
2019-05-01 21:56   ` Tobin C. Harding
2019-05-02  7:17     ` Greg Kroah-Hartman
2019-05-02  7:28       ` Greg Kroah-Hartman
2019-05-02  8:19         ` Tobin C. Harding
2019-05-02 10:22           ` [PATCH] kobject: clean up the kobject add documentation a bit more Greg Kroah-Hartman
2019-05-03  1:25             ` Tobin C. Harding
2019-05-03  6:27               ` Greg Kroah-Hartman

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:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

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

  git send-email \
    --in-reply-to=20190428161458.GB13309@kroah.com \
    --to=gregkh@linuxfoundation.org \
    --cc=cl@linux.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=me@tobin.cc \
    --cc=rafael@kernel.org \
    --cc=tycho@tycho.ws \
    --cc=willy@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* 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

all inboxes | Powered by JetHome®