Commit cfb36fff authored by Greg Kroah-Hartman's avatar Greg Kroah-Hartman

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: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent d76e15fb
...@@ -133,7 +133,6 @@ void kobject_init(struct kobject * kobj) ...@@ -133,7 +133,6 @@ void kobject_init(struct kobject * kobj)
return; return;
kref_init(&kobj->kref); kref_init(&kobj->kref);
INIT_LIST_HEAD(&kobj->entry); INIT_LIST_HEAD(&kobj->entry);
kobj->kset = kset_get(kobj->kset);
} }
...@@ -184,7 +183,7 @@ int kobject_add(struct kobject * kobj) ...@@ -184,7 +183,7 @@ int kobject_add(struct kobject * kobj)
kobj->kset ? kobject_name(&kobj->kset->kobj) : "<NULL>" ); kobj->kset ? kobject_name(&kobj->kset->kobj) : "<NULL>" );
if (kobj->kset) { if (kobj->kset) {
spin_lock(&kobj->kset->list_lock); kobj->kset = kset_get(kobj->kset);
if (!parent) { if (!parent) {
parent = kobject_get(&kobj->kset->kobj); parent = kobject_get(&kobj->kset->kobj);
...@@ -196,7 +195,8 @@ int kobject_add(struct kobject * kobj) ...@@ -196,7 +195,8 @@ int kobject_add(struct kobject * kobj)
kobject_get(parent); 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); spin_unlock(&kobj->kset->list_lock);
kobj->parent = parent; kobj->parent = parent;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment