[PATCH 10/13] driver-core: add for_each_class()

From: Tomeu Vizoso
Date: Wed Jun 17 2015 - 09:44:56 EST


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@xxxxxxxxxxxxx>
---
drivers/base/base.h | 2 ++
drivers/base/class.c | 16 ++++++++++++++++
2 files changed, 18 insertions(+)

diff --git a/drivers/base/base.h b/drivers/base/base.h
index 29c985e..be81c88 100644
--- a/drivers/base/base.h
+++ b/drivers/base/base.h
@@ -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);
diff --git a/drivers/base/class.c b/drivers/base/class.c
index 6e81088..f4114a4 100644
--- a/drivers/base/class.c
+++ b/drivers/base/class.c
@@ -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);
--
2.4.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/