diff --git a/include/linux/kobject.h b/include/linux/kobject.h index bdab370a24f4ef6f77cf4e5b3d9cddbd5a5ad137..c5f8878836e06e0ff5800f54ef0de12b7b242bb4 100644 --- a/include/linux/kobject.h +++ b/include/linux/kobject.h @@ -205,6 +205,8 @@ static inline const struct kobj_type *get_ktype(const struct kobject *kobj) extern struct kobject *kset_find_obj(struct kset *, const char *); +struct kobject *kset_get_next_obj(struct kset *kset, struct kobject *prev); + /* The global /sys/kernel/ kobject for people to chain off of */ extern struct kobject *kernel_kobj; /* The global /sys/kernel/mm/ kobject for people to chain off of */ diff --git a/lib/kobject.c b/lib/kobject.c index 6e2f0bee356042c8fd485e4992873d3f9069f8d8..cbf41f3be53b76dcc927f3442d23fd165adedd14 100644 --- a/lib/kobject.c +++ b/lib/kobject.c @@ -907,6 +907,27 @@ struct kobject *kset_find_obj(struct kset *kset, const char *name) } EXPORT_SYMBOL_GPL(kset_find_obj); +struct kobject *kset_get_next_obj(struct kset *kset, struct kobject *prev) +{ + struct kobject *k; + + spin_lock(&kset->list_lock); + + if (!prev) + k = list_first_entry_or_null(&kset->list, typeof(*k), entry); + else + k = list_next_entry(prev, entry); + + if (list_entry_is_head(k, &kset->list, entry)) + k = NULL; + + kobject_get(k); + spin_unlock(&kset->list_lock); + kobject_put(prev); + + return k; +} + static void kset_release(struct kobject *kobj) { struct kset *kset = container_of(kobj, struct kset, kobj);