summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/kobject.c15
-rw-r--r--lib/kref.c11
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);