Commit 7dd6e94e authored by Patrick Mochel's avatar Patrick Mochel

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. 
parent c3016fe6
......@@ -87,6 +87,9 @@ static inline void kset_put(struct kset * k)
}
extern struct kobject * kset_find_obj(struct kset *, char *);
struct subsystem {
struct kset kset;
struct rw_semaphore rwsem;
......
......@@ -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);
......
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