aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorPatrick Mochel <mochel@osdl.org>2003-01-06 09:20:40 -0600
committerPatrick Mochel <mochel@osdl.org>2003-01-06 09:20:40 -0600
commit7dd6e94ed51400dd897b8bf3f791baaa61cbbf22 (patch)
tree380c8f3956a4b4c20b3d1fd42f01e87fee254461 /lib
parentc3016fe6abf9a2baf8accbe22ef964d506bd9e8a (diff)
downloadhistory-7dd6e94ed51400dd897b8bf3f791baaa61cbbf22.tar.gz
add kset_find_obj() to search for object in a kset's list.
The operation is simple: - Take read lock for kset. - Iterate over kset->list. - Compare name to each kobject's name. - Return kobject if found.
Diffstat (limited to 'lib')
-rw-r--r--lib/kobject.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/lib/kobject.c b/lib/kobject.c
index 59872973992a17..c0857237f8e6b9 100644
--- a/lib/kobject.c
+++ b/lib/kobject.c
@@ -61,6 +61,12 @@ static int create_dir(struct kobject * kobj)
}
+static inline struct kobject * to_kobj(struct list_head * entry)
+{
+ return container_of(entry,struct kobject,entry);
+}
+
+
/**
* kobject_init - initialize object.
* @kobj: object in question.
@@ -264,6 +270,33 @@ void kset_unregister(struct kset * k)
}
+/**
+ * kset_find_obj - search for object in kset.
+ * @kset: kset we're looking in.
+ * @name: object's name.
+ *
+ * Lock kset via @kset->subsys, and iterate over @kset->list,
+ * looking for a matching kobject. Return object if found.
+ */
+
+struct kobject * kset_find_obj(struct kset * kset, char * name)
+{
+ struct list_head * entry;
+ struct kobject * ret = NULL;
+
+ down_read(&kset->subsys->rwsem);
+ list_for_each(entry,&kset->list) {
+ struct kobject * k = to_kobj(entry);
+ if (!strcmp(k->name,name)) {
+ ret = k;
+ break;
+ }
+ }
+ up_read(&kset->subsys->rwsem);
+ return ret;
+}
+
+
void subsystem_init(struct subsystem * s)
{
init_rwsem(&s->rwsem);