aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorGreg Kroah-Hartman <gregkh@suse.de>2007-11-28 13:46:22 -0500
committerGreg Kroah-Hartman <gregkh@suse.de>2008-01-24 23:40:25 -0500
commitcfb36fff45e3997b8044c81045fc4869ba5f281a (patch)
tree35a58ea81b5864bfd68b8de65c791cf92729b072 /lib
parentd76e15fb20eeb7632ef38876a884fe3508b2c01d (diff)
kobject: grab the kset reference in kobject_add, not kobject_init
kobject_init should not be grabing any references, but only initializing the object. This patch fixes this, and makes the lock hold-time shorter for when a kset is present in the kobject. The current kernel tree has been audited to verify that this change should be safe. Cc: Kay Sievers <kay.sievers@vrfy.org> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'lib')
-rw-r--r--lib/kobject.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/lib/kobject.c b/lib/kobject.c
index 7919c32a3a15..4d52b6f534bc 100644
--- a/lib/kobject.c
+++ b/lib/kobject.c
@@ -133,7 +133,6 @@ void kobject_init(struct kobject * kobj)
133 return; 133 return;
134 kref_init(&kobj->kref); 134 kref_init(&kobj->kref);
135 INIT_LIST_HEAD(&kobj->entry); 135 INIT_LIST_HEAD(&kobj->entry);
136 kobj->kset = kset_get(kobj->kset);
137} 136}
138 137
139 138
@@ -184,7 +183,7 @@ int kobject_add(struct kobject * kobj)
184 kobj->kset ? kobject_name(&kobj->kset->kobj) : "<NULL>" ); 183 kobj->kset ? kobject_name(&kobj->kset->kobj) : "<NULL>" );
185 184
186 if (kobj->kset) { 185 if (kobj->kset) {
187 spin_lock(&kobj->kset->list_lock); 186 kobj->kset = kset_get(kobj->kset);
188 187
189 if (!parent) { 188 if (!parent) {
190 parent = kobject_get(&kobj->kset->kobj); 189 parent = kobject_get(&kobj->kset->kobj);
@@ -196,7 +195,8 @@ int kobject_add(struct kobject * kobj)
196 kobject_get(parent); 195 kobject_get(parent);
197 } 196 }
198 197
199 list_add_tail(&kobj->entry,&kobj->kset->list); 198 spin_lock(&kobj->kset->list_lock);
199 list_add_tail(&kobj->entry, &kobj->kset->list);
200 spin_unlock(&kobj->kset->list_lock); 200 spin_unlock(&kobj->kset->list_lock);
201 kobj->parent = parent; 201 kobj->parent = parent;
202 } 202 }