]> err.no Git - linux-2.6/blobdiff - lib/kobject.c
klist: implement klist_add_{after|before}()
[linux-2.6] / lib / kobject.c
index d784daeb8571692e0fed288f17df60651a04366c..fd78740321639afdf10438ed1890a5a61be15c18 100644 (file)
@@ -58,11 +58,6 @@ static int create_dir(struct kobject *kobj)
        return error;
 }
 
-static inline struct kobject *to_kobj(struct list_head *entry)
-{
-       return container_of(entry, struct kobject, entry);
-}
-
 static int get_kobj_path_length(struct kobject *kobj)
 {
        int length = 1;
@@ -95,7 +90,7 @@ static void fill_kobj_path(struct kobject *kobj, char *path, int length)
        }
 
        pr_debug("kobject: '%s' (%p): %s: path = '%s'\n", kobject_name(kobj),
-                kobj, __FUNCTION__, path);
+                kobj, __func__, path);
 }
 
 /**
@@ -153,6 +148,10 @@ static void kobject_init_internal(struct kobject *kobj)
                return;
        kref_init(&kobj->kref);
        INIT_LIST_HEAD(&kobj->entry);
+       kobj->state_in_sysfs = 0;
+       kobj->state_add_uevent_sent = 0;
+       kobj->state_remove_uevent_sent = 0;
+       kobj->state_initialized = 1;
 }
 
 
@@ -182,7 +181,7 @@ static int kobject_add_internal(struct kobject *kobj)
        }
 
        pr_debug("kobject: '%s' (%p): %s: parent: '%s', set: '%s'\n",
-                kobject_name(kobj), kobj, __FUNCTION__,
+                kobject_name(kobj), kobj, __func__,
                 parent ? kobject_name(parent) : "<NULL>",
                 kobj->kset ? kobject_name(&kobj->kset->kobj) : "<NULL>");
 
@@ -197,10 +196,10 @@ static int kobject_add_internal(struct kobject *kobj)
                        printk(KERN_ERR "%s failed for %s with "
                               "-EEXIST, don't try to register things with "
                               "the same name in the same directory.\n",
-                              __FUNCTION__, kobject_name(kobj));
+                              __func__, kobject_name(kobj));
                else
                        printk(KERN_ERR "%s failed for %s (%d)\n",
-                              __FUNCTION__, kobject_name(kobj), error);
+                              __func__, kobject_name(kobj), error);
                dump_stack();
        } else
                kobj->state_in_sysfs = 1;
@@ -289,13 +288,8 @@ void kobject_init(struct kobject *kobj, struct kobj_type *ktype)
                dump_stack();
        }
 
-       kref_init(&kobj->kref);
-       INIT_LIST_HEAD(&kobj->entry);
+       kobject_init_internal(kobj);
        kobj->ktype = ktype;
-       kobj->state_in_sysfs = 0;
-       kobj->state_add_uevent_sent = 0;
-       kobj->state_remove_uevent_sent = 0;
-       kobj->state_initialized = 1;
        return;
 
 error:
@@ -546,7 +540,7 @@ static void kobject_cleanup(struct kobject *kobj)
        const char *name = kobj->name;
 
        pr_debug("kobject: '%s' (%p): %s\n",
-                kobject_name(kobj), kobj, __FUNCTION__);
+                kobject_name(kobj), kobj, __func__);
 
        if (t && !t->release)
                pr_debug("kobject: '%s' (%p): does not have a release() "
@@ -593,13 +587,20 @@ static void kobject_release(struct kref *kref)
  */
 void kobject_put(struct kobject *kobj)
 {
-       if (kobj)
+       if (kobj) {
+               if (!kobj->state_initialized) {
+                       printk(KERN_WARNING "kobject: '%s' (%p): is not "
+                              "initialized, yet kobject_put() is being "
+                              "called.\n", kobject_name(kobj), kobj);
+                       WARN_ON(1);
+               }
                kref_put(&kobj->kref, kobject_release);
+       }
 }
 
 static void dynamic_kobj_release(struct kobject *kobj)
 {
-       pr_debug("kobject: (%p): %s\n", kobj, __FUNCTION__);
+       pr_debug("kobject: (%p): %s\n", kobj, __func__);
        kfree(kobj);
 }
 
@@ -656,7 +657,7 @@ struct kobject *kobject_create_and_add(const char *name, struct kobject *parent)
        retval = kobject_add(kobj, parent, "%s", name);
        if (retval) {
                printk(KERN_WARNING "%s: kobject_add error: %d\n",
-                      __FUNCTION__, retval);
+                      __func__, retval);
                kobject_put(kobj);
                kobj = NULL;
        }
@@ -746,12 +747,11 @@ void kset_unregister(struct kset *k)
  */
 struct kobject *kset_find_obj(struct kset *kset, const char *name)
 {
-       struct list_head *entry;
+       struct kobject *k;
        struct kobject *ret = NULL;
 
        spin_lock(&kset->list_lock);
-       list_for_each(entry, &kset->list) {
-               struct kobject *k = to_kobj(entry);
+       list_for_each_entry(k, &kset->list, entry) {
                if (kobject_name(k) && !strcmp(kobject_name(k), name)) {
                        ret = kobject_get(k);
                        break;
@@ -765,7 +765,7 @@ static void kset_release(struct kobject *kobj)
 {
        struct kset *kset = container_of(kobj, struct kset, kobj);
        pr_debug("kobject: '%s' (%p): %s\n",
-                kobject_name(kobj), kobj, __FUNCTION__);
+                kobject_name(kobj), kobj, __func__);
        kfree(kset);
 }