]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - lib/kobject.c
[MIPS] rbhma4500: use generic txx9 gpio
[linux-2.6-omap-h63xx.git] / lib / kobject.c
index 1d63ead1815e4f5cb8aae5ea2d86a1541eed23a2..2c6490370922ccddf939db20e6bf0b71fcbf9526 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;
@@ -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;
 }
 
 
@@ -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:
@@ -593,8 +587,15 @@ 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)
@@ -637,7 +638,7 @@ struct kobject *kobject_create(void)
  * @name: the name for the kset
  * @parent: the parent kobject of this kobject, if any.
  *
- * This function creates a kset structure dynamically and registers it
+ * This function creates a kobject structure dynamically and registers it
  * with sysfs.  When you are finished with this structure, call
  * kobject_put() and the structure will be dynamically freed when
  * it is no longer being used.
@@ -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;