From c1ebdae514a356c71c09035f5141d94aab5e8fe4 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Tue, 26 Feb 2008 09:36:38 -0800 Subject: kobject: catch kobjects that are not initialized Add warnings to kobject_put() to catch kobjects that are cleaned up but were never initialized to begin with. Cc: Kay Sievers Cc: Hannes Reinecke Signed-off-by: Greg Kroah-Hartman --- lib/kobject.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/kobject.c b/lib/kobject.c index 0d03252f87a8..60ae9e817663 100644 --- a/lib/kobject.c +++ b/lib/kobject.c @@ -592,8 +592,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) -- cgit v1.2.1 From c6a2a3dc26da72e431c293d02549593f9c041f63 Mon Sep 17 00:00:00 2001 From: "Robert P. J. Day" Date: Thu, 27 Mar 2008 01:13:34 -0400 Subject: Kobject: Replace list_for_each() with list_for_each_entry(). Use the more concise list_for_each_entry(), which allows for the deletion of the to_kobj() routine at the same time. Signed-off-by: Robert P. J. Day Signed-off-by: Greg Kroah-Hartman --- lib/kobject.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) (limited to 'lib') diff --git a/lib/kobject.c b/lib/kobject.c index 60ae9e817663..2c6490370922 100644 --- a/lib/kobject.c +++ b/lib/kobject.c @@ -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; @@ -752,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; -- cgit v1.2.1