]> git.neil.brown.name Git - history.git/commitdiff
kobject: fix bug where a parent could be deleted before a child device.
authorGreg Kroah-Hartman <greg@kroah.com>
Thu, 11 Dec 2003 01:49:24 +0000 (17:49 -0800)
committerGreg Kroah-Hartman <greg@kroah.com>
Thu, 11 Dec 2003 01:49:24 +0000 (17:49 -0800)
lib/kobject.c

index ff65c0f2c98fcf49ed91ec887950bf8c7879f1b7..51787be15552626f1e7f1475ea6895ed1e83e1b9 100644 (file)
@@ -236,8 +236,6 @@ static void unlink(struct kobject * kobj)
                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 @@ int kobject_add(struct kobject * kobj)
        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 @@ void kobject_cleanup(struct kobject * kobj)
 {
        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 @@ void kobject_cleanup(struct kobject * kobj)
                t->release(kobj);
        if (s)
                kset_put(s);
+       if (parent) 
+               kobject_put(parent);
 }
 
 /**