LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Greg KH <greg@kroah.com>
To: Roland Dreier <rdreier@cisco.com>
Cc: linux-kernel@vger.kernel.org
Subject: Re: kobject must be initialized before calling kobject_init()?!
Date: Fri, 8 Feb 2008 21:15:39 -0800	[thread overview]
Message-ID: <20080209051539.GA28565@kroah.com> (raw)
In-Reply-To: <adaabma21vq.fsf@cisco.com>

On Fri, Feb 08, 2008 at 08:24:25PM -0800, Roland Dreier wrote:
> So I was perusing the code in lib/kobject.c, and I saw this:
> 
> 	void kobject_init(struct kobject *kobj, struct kobj_type *ktype)
> 	{
> 		// [a couple of of parameter checks...]
> 		if (kobj->state_initialized) {
> 			/* do not error out as sometimes we can recover */
> 			printk(KERN_ERR "kobject (%p): tried to init an initialized "
> 			       "object, something is seriously wrong.\n", kobj);
> 			dump_stack();
> 		}
> 
> in other words the first thing you do is check a member of the
> structure you're supposed to be initializing -- if someone just
> kmalloc()s a struct kobject and passes it into this function, there's
> a good chance that state_initialized won't be zero.  In fact, with
> slab debugging on, it's guaranteed to be poisoned with a non-zero
> value.
> 
> So are users supposed to be zeroing out struct kobjects before
> initializing them?

Yes.  See also the check about the non-zero reference count when
initializing the kref, that too will trip.

> If so, this should probably be documented.

You're right.  Patches gladly accepted :)

thanks,

greg k-h

      reply	other threads:[~2008-02-09  5:11 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-02-09  4:24 Roland Dreier
2008-02-09  5:15 ` Greg KH [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:
  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=20080209051539.GA28565@kroah.com \
    --to=greg@kroah.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rdreier@cisco.com \
    --subject='Re: kobject must be initialized before calling kobject_init()?'\!'' \
    /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

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).