diff options
| author | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-03-09 01:11:30 -0800 |
|---|---|---|
| committer | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-03-09 01:11:30 -0800 |
| commit | 0a983298a21165bd7321bd02de6f166293e2d884 (patch) | |
| tree | c4fbf4fa71aa38f63c38a17001e024a0bc8f6fd1 /lib | |
| parent | aa61674d1a2a026449e00de79d36fb921c13fe16 (diff) | |
| parent | 0c156ba8ede6d99bd1738d7d987d9d58f65d0aa9 (diff) | |
Merge bk://kernel.bkbits.net/gregkh/linux/2.6.11/driver
into ppc970.osdl.org:/home/torvalds/v2.6/linux
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/kobject.c | 15 | ||||
| -rw-r--r-- | lib/kref.c | 11 |
2 files changed, 16 insertions, 10 deletions
diff --git a/lib/kobject.c b/lib/kobject.c index 8737dfd72d36..ff9491986b38 100644 --- a/lib/kobject.c +++ b/lib/kobject.c @@ -140,9 +140,9 @@ void kobject_init(struct kobject * kobj) static void unlink(struct kobject * kobj) { if (kobj->kset) { - down_write(&kobj->kset->subsys->rwsem); + spin_lock(&kobj->kset->list_lock); list_del_init(&kobj->entry); - up_write(&kobj->kset->subsys->rwsem); + spin_unlock(&kobj->kset->list_lock); } kobject_put(kobj); } @@ -168,13 +168,13 @@ int kobject_add(struct kobject * kobj) kobj->kset ? kobj->kset->kobj.name : "<NULL>" ); if (kobj->kset) { - down_write(&kobj->kset->subsys->rwsem); + spin_lock(&kobj->kset->list_lock); if (!parent) parent = kobject_get(&kobj->kset->kobj); list_add_tail(&kobj->entry,&kobj->kset->list); - up_write(&kobj->kset->subsys->rwsem); + spin_unlock(&kobj->kset->list_lock); } kobj->parent = parent; @@ -380,6 +380,7 @@ void kset_init(struct kset * k) { kobject_init(&k->kobj); INIT_LIST_HEAD(&k->list); + spin_lock_init(&k->list_lock); } @@ -444,7 +445,7 @@ struct kobject * kset_find_obj(struct kset * kset, const char * name) struct list_head * entry; struct kobject * ret = NULL; - down_read(&kset->subsys->rwsem); + spin_lock(&kset->list_lock); list_for_each(entry,&kset->list) { struct kobject * k = to_kobj(entry); if (kobject_name(k) && !strcmp(kobject_name(k),name)) { @@ -452,7 +453,7 @@ struct kobject * kset_find_obj(struct kset * kset, const char * name) break; } } - up_read(&kset->subsys->rwsem); + spin_unlock(&kset->list_lock); return ret; } @@ -524,7 +525,6 @@ void subsys_remove_file(struct subsystem * s, struct subsys_attribute * a) } } -EXPORT_SYMBOL(kobject_get_path); EXPORT_SYMBOL(kobject_init); EXPORT_SYMBOL(kobject_register); EXPORT_SYMBOL(kobject_unregister); @@ -532,7 +532,6 @@ EXPORT_SYMBOL(kobject_get); EXPORT_SYMBOL(kobject_put); EXPORT_SYMBOL(kobject_add); EXPORT_SYMBOL(kobject_del); -EXPORT_SYMBOL(kobject_rename); EXPORT_SYMBOL(kset_register); EXPORT_SYMBOL(kset_unregister); diff --git a/lib/kref.c b/lib/kref.c index 2218b7ae7db6..0d07cc31c818 100644 --- a/lib/kref.c +++ b/lib/kref.c @@ -42,14 +42,21 @@ void kref_get(struct kref *kref) * in as this function. * * Decrement the refcount, and if 0, call release(). + * Return 1 if the object was removed, otherwise return 0. Beware, if this + * function returns 0, you still can not count on the kref from remaining in + * memory. Only use the return value if you want to see if the kref is now + * gone, not present. */ -void kref_put(struct kref *kref, void (*release) (struct kref *kref)) +int kref_put(struct kref *kref, void (*release)(struct kref *kref)) { WARN_ON(release == NULL); WARN_ON(release == (void (*)(struct kref *))kfree); - if (atomic_dec_and_test(&kref->refcount)) + if (atomic_dec_and_test(&kref->refcount)) { release(kref); + return 1; + } + return 0; } EXPORT_SYMBOL(kref_init); |
