@@ -149,3 +149,5 @@ extern int devtmpfs_init(void);
#else
static inline int devtmpfs_init(void) { return 0; }
#endif
+
+extern void for_each_class(void (*fn)(struct class *, void *), void *data);
@@ -583,6 +583,22 @@ void class_compat_remove_link(struct class_compat *cls, struct device *dev,
}
EXPORT_SYMBOL_GPL(class_compat_remove_link);
+void for_each_class(void (*fn)(struct class *, void *), void *data)
+{
+ struct subsys_private *cp;
+ struct kobject *k;
+
+ if (!class_kset)
+ return;
+
+ list_for_each_entry(k, &class_kset->list, entry) {
+ cp = to_subsys_private(k);
+ class_get(cp->class);
+ fn(cp->class, data);
+ class_put(cp->class);
+ }
+}
+
int __init classes_init(void)
{
class_kset = kset_create_and_add("class", NULL, NULL);
The purpose of this function is to allow other parts of the driver core to iterate over the currently registered classes. Signed-off-by: Tomeu Vizoso <tomeu.vizoso@collabora.com> --- drivers/base/base.h | 2 ++ drivers/base/class.c | 16 ++++++++++++++++ 2 files changed, 18 insertions(+)