Kobject: rename kobject_add_ng() to kobject_add()
[firefly-linux-kernel-4.4.55.git] / lib / kobject.c
index 7919c32a3a15888bcc92b29b9d898db530fb1107..359e114790cb40a9e477bb9374660e8f182f733e 100644 (file)
@@ -95,7 +95,8 @@ static void fill_kobj_path(struct kobject *kobj, char *path, int length)
                *(path + --length) = '/';
        }
 
-       pr_debug("%s: path = '%s'\n",__FUNCTION__,path);
+       pr_debug("kobject: '%s' (%p): %s: path = '%s'\n", kobject_name(kobj),
+                kobj, __FUNCTION__,path);
 }
 
 /**
@@ -133,7 +134,6 @@ void kobject_init(struct kobject * kobj)
                return;
        kref_init(&kobj->kref);
        INIT_LIST_HEAD(&kobj->entry);
-       kobj->kset = kset_get(kobj->kset);
 }
 
 
@@ -144,25 +144,24 @@ void kobject_init(struct kobject * kobj)
  *     Remove the kobject from the kset list and decrement
  *     its parent's refcount.
  *     This is separated out, so we can use it in both 
- *     kobject_del() and kobject_add() on error.
+ *     kobject_del() and kobject_add_internal() on error.
  */
 
 static void unlink(struct kobject * kobj)
 {
+       struct kobject *parent = kobj->parent;
+
        if (kobj->kset) {
                spin_lock(&kobj->kset->list_lock);
                list_del_init(&kobj->entry);
                spin_unlock(&kobj->kset->list_lock);
        }
+       kobj->parent = NULL;
        kobject_put(kobj);
+       kobject_put(parent);
 }
 
-/**
- *     kobject_add - add an object to the hierarchy.
- *     @kobj:  object.
- */
-
-int kobject_add(struct kobject * kobj)
+static int kobject_add_internal(struct kobject *kobj)
 {
        int error = 0;
        struct kobject * parent;
@@ -172,19 +171,21 @@ int kobject_add(struct kobject * kobj)
        if (!kobj->k_name)
                kobject_set_name(kobj, "NO_NAME");
        if (!*kobj->k_name) {
-               pr_debug("kobject attempted to be registered with no name!\n");
+               pr_debug("kobject (%p) attempted to be registered with no "
+                        "name!\n", kobj);
                WARN_ON(1);
                kobject_put(kobj);
                return -EINVAL;
        }
        parent = kobject_get(kobj->parent);
 
-       pr_debug("kobject %s: registering. parent: %s, set: %s\n",
-                kobject_name(kobj), parent ? kobject_name(parent) : "<NULL>", 
+       pr_debug("kobject: '%s' (%p): %s: parent: '%s', set: '%s'\n",
+                kobject_name(kobj), kobj, __FUNCTION__,
+                parent ? kobject_name(parent) : "<NULL>",
                 kobj->kset ? kobject_name(&kobj->kset->kobj) : "<NULL>" );
 
        if (kobj->kset) {
-               spin_lock(&kobj->kset->list_lock);
+               kobj->kset = kset_get(kobj->kset);
 
                if (!parent) {
                        parent = kobject_get(&kobj->kset->kobj);
@@ -196,7 +197,8 @@ int kobject_add(struct kobject * kobj)
                        kobject_get(parent);
                }
 
-               list_add_tail(&kobj->entry,&kobj->kset->list);
+               spin_lock(&kobj->kset->list_lock);
+               list_add_tail(&kobj->entry, &kobj->kset->list);
                spin_unlock(&kobj->kset->list_lock);
                kobj->parent = parent;
        }
@@ -205,17 +207,16 @@ int kobject_add(struct kobject * kobj)
        if (error) {
                /* unlink does the kobject_put() for us */
                unlink(kobj);
-               kobject_put(parent);
 
                /* be noisy on error issues */
                if (error == -EEXIST)
-                       printk(KERN_ERR "kobject_add failed for %s with "
+                       printk(KERN_ERR "%s failed for %s with "
                               "-EEXIST, don't try to register things with "
                               "the same name in the same directory.\n",
-                              kobject_name(kobj));
+                              __FUNCTION__, kobject_name(kobj));
                else
-                       printk(KERN_ERR "kobject_add failed for %s (%d)\n",
-                              kobject_name(kobj), error);
+                       printk(KERN_ERR "%s failed for %s (%d)\n",
+                              __FUNCTION__, kobject_name(kobj), error);
                dump_stack();
        }
 
@@ -345,11 +346,11 @@ static int kobject_add_varg(struct kobject *kobj, struct kobject *parent,
                return retval;
        }
        kobj->parent = parent;
-       return kobject_add(kobj);
+       return kobject_add_internal(kobj);
 }
 
 /**
- * kobject_add_ng - the main kobject add function
+ * kobject_add - the main kobject add function
  * @kobj: the kobject to add
  * @parent: pointer to the parent of the kobject.
  * @fmt: format to name the kobject with.
@@ -380,8 +381,8 @@ static int kobject_add_varg(struct kobject *kobj, struct kobject *parent,
  * kobject_uevent() with the UEVENT_ADD parameter to ensure that
  * userspace is properly notified of this kobject's creation.
  */
-int kobject_add_ng(struct kobject *kobj, struct kobject *parent,
-                  const char *fmt, ...)
+int kobject_add(struct kobject *kobj, struct kobject *parent,
+               const char *fmt, ...)
 {
        va_list args;
        int retval;
@@ -395,7 +396,7 @@ int kobject_add_ng(struct kobject *kobj, struct kobject *parent,
 
        return retval;
 }
-EXPORT_SYMBOL(kobject_add_ng);
+EXPORT_SYMBOL(kobject_add);
 
 /**
  * kobject_init_and_add - initialize a kobject structure and add it to the kobject hierarchy
@@ -405,8 +406,8 @@ EXPORT_SYMBOL(kobject_add_ng);
  * @fmt: the name of the kobject.
  *
  * This function combines the call to kobject_init_ng() and
- * kobject_add_ng().  The same type of error handling after a call to
- * kobject_add_ng() and kobject lifetime rules are the same here.
+ * kobject_add().  The same type of error handling after a call to
+ * kobject_add() and kobject lifetime rules are the same here.
  */
 int kobject_init_and_add(struct kobject *kobj, struct kobj_type *ktype,
                         struct kobject *parent, const char *fmt, ...)
@@ -560,7 +561,8 @@ void kobject_unregister(struct kobject * kobj)
 {
        if (!kobj)
                return;
-       pr_debug("kobject %s: unregistering\n",kobject_name(kobj));
+       pr_debug("kobject: '%s' (%p): %s\n",
+                kobject_name(kobj), kobj, __FUNCTION__);
        kobject_uevent(kobj, KOBJ_REMOVE);
        kobject_del(kobj);
        kobject_put(kobj);
@@ -586,10 +588,10 @@ static void kobject_cleanup(struct kobject *kobj)
 {
        struct kobj_type * t = get_ktype(kobj);
        struct kset * s = kobj->kset;
-       struct kobject * parent = kobj->parent;
        const char *name = kobj->k_name;
 
-       pr_debug("kobject %s: cleaning up\n",kobject_name(kobj));
+       pr_debug("kobject: '%s' (%p): %s\n",
+                kobject_name(kobj), kobj, __FUNCTION__);
        if (t && t->release) {
                t->release(kobj);
                /* If we have a release function, we can guess that this was
@@ -599,7 +601,6 @@ static void kobject_cleanup(struct kobject *kobj)
        }
        if (s)
                kset_put(s);
-       kobject_put(parent);
 }
 
 static void kobject_release(struct kref *kref)
@@ -621,7 +622,8 @@ void kobject_put(struct kobject * kobj)
 
 static void dynamic_kobj_release(struct kobject *kobj)
 {
-       pr_debug("%s: freeing %s\n", __FUNCTION__, kobject_name(kobj));
+       pr_debug("kobject: '%s' (%p): %s\n",
+                kobject_name(kobj), kobj, __FUNCTION__);
        kfree(kobj);
 }
 
@@ -675,7 +677,7 @@ struct kobject *kobject_create_and_add(const char *name, struct kobject *parent)
        if (!kobj)
                return NULL;
 
-       retval = kobject_add_ng(kobj, parent, "%s", name);
+       retval = kobject_add(kobj, parent, "%s", name);
        if (retval) {
                printk(KERN_WARNING "%s: kobject_add error: %d\n",
                       __FUNCTION__, retval);
@@ -735,7 +737,7 @@ struct sysfs_ops kobj_sysfs_ops = {
 
 int kset_add(struct kset * k)
 {
-       return kobject_add(&k->kobj);
+       return kobject_add_internal(&k->kobj);
 }
 
 
@@ -803,7 +805,8 @@ struct kobject * kset_find_obj(struct kset * kset, const char * name)
 static void kset_release(struct kobject *kobj)
 {
        struct kset *kset = container_of(kobj, struct kset, kobj);
-       pr_debug("kset %s: now freed\n", kobject_name(kobj));
+       pr_debug("kobject: '%s' (%p): %s\n",
+                kobject_name(kobj), kobj, __FUNCTION__);
        kfree(kset);
 }
 
@@ -889,7 +892,6 @@ EXPORT_SYMBOL(kobject_register);
 EXPORT_SYMBOL(kobject_unregister);
 EXPORT_SYMBOL(kobject_get);
 EXPORT_SYMBOL(kobject_put);
-EXPORT_SYMBOL(kobject_add);
 EXPORT_SYMBOL(kobject_del);
 
 EXPORT_SYMBOL(kset_register);