public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Greg KH <greg@kroah.com>
To: Andrew Morton <akpm@osdl.org>,
	maneesh@in.ibm.com, mgorse@mgorse.dhs.org,
	linux-kernel@vger.kernel.org,
	Andrey Borzenkov <arvidjaar@mail.ru>,
	Patrick Mochel <mochel@digitalimplant.org>
Subject: Re: oopses in kobjects in 2.6.0-test11 (was Re: kobject patch)
Date: Mon, 8 Dec 2003 14:58:40 -0800	[thread overview]
Message-ID: <20031208225840.GA31245@kroah.com> (raw)
In-Reply-To: <20031208224810.GB31134@kroah.com>

On Mon, Dec 08, 2003 at 02:48:10PM -0800, Greg KH wrote:
> 
> Ok, here's how a parent can be removed from the system without the child
> going away:
> 	- create parent and register it successfully.
> 	- create child, call kobject_add() which increments the count of
> 	  the parent.
> 	- call kobject_get() on the child.
> 	- call kobject_del() on the parent.  This will keep the parent
> 	  around, as the child still has a reference on it.
> 	- call kobject_del() on the child.  This will decrement the
> 	  count on the parent due to the call in unlink().  That will
> 	  free the parent up from memory.  But this child still has a
> 	  incremented count (rightly, as it is in use).
> 	  
> 	- So the child now has a stale parent pointer, causing all sorts
> 	  of fun...
> 
> I'll work on a patch for kobject.c and post it in the next message, and
> include the original message and patch below for others to see.

Here's a patch for kobject.c that should fix this problem and keep
kobject parent's around until after the child is gone.  Please can
someone verify that I didn't get this wrong...

thanks,

greg k-h

--- a/lib/kobject.c	Mon Sep 29 15:13:44 2003
+++ b/lib/kobject.c	Mon Dec  8 14:56:32 2003
@@ -236,8 +236,6 @@
 		list_del_init(&kobj->entry);
 		up_write(&kobj->kset->subsys->rwsem);
 	}
-	if (kobj->parent) 
-		kobject_put(kobj->parent);
 	kobject_put(kobj);
 }
 
@@ -274,9 +272,11 @@
 	kobj->parent = parent;
 
 	error = create_dir(kobj);
-	if (error)
+	if (error) {
 		unlink(kobj);
-	else {
+		if (parent)
+			kobject_put(parent);
+	} else {
 		/* If this kobj does not belong to a kset,
 		   try to find a parent that does. */
 		top_kobj = kobj;
@@ -452,6 +452,7 @@
 {
 	struct kobj_type * t = get_ktype(kobj);
 	struct kset * s = kobj->kset;
+	struct kobject * parent = kobj->parent;
 
 	pr_debug("kobject %s: cleaning up\n",kobject_name(kobj));
 	if (kobj->k_name != kobj->name)
@@ -461,6 +462,8 @@
 		t->release(kobj);
 	if (s)
 		kset_put(s);
+	if (parent) 
+		kobject_put(parent);
 }
 
 /**

  reply	other threads:[~2003-12-08 23:01 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20031009014837.4ff71634.akpm@osdl.org>
     [not found] ` <20031208222526.GA31134@kroah.com>
2003-12-08 22:48   ` oopses in kobjects in 2.6.0-test11 (was Re: kobject patch) Greg KH
2003-12-08 22:58     ` Greg KH [this message]
2003-12-11 16:51       ` Patrick Mochel
2003-12-11 17:50         ` Greg KH
2003-12-28 12:38     ` Andrey Borzenkov
2003-12-30  0:32       ` Greg KH

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=20031208225840.GA31245@kroah.com \
    --to=greg@kroah.com \
    --cc=akpm@osdl.org \
    --cc=arvidjaar@mail.ru \
    --cc=linux-kernel@vger.kernel.org \
    --cc=maneesh@in.ibm.com \
    --cc=mgorse@mgorse.dhs.org \
    --cc=mochel@digitalimplant.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