wpan-phy: add wpan-phy iteration functions
authorDmitry Eremin-Solenikov <dbaryshkov@gmail.com>
Tue, 15 Sep 2009 12:57:04 +0000 (16:57 +0400)
committerDmitry Eremin-Solenikov <dbaryshkov@gmail.com>
Fri, 6 Nov 2009 11:12:24 +0000 (14:12 +0300)
Add API to iterate over the wpan-phy instances.

Signed-off-by: Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
include/net/wpan-phy.h
net/ieee802154/wpan-class.c

index 5e803a0e4e72837bf8bb27fe881a8257673a0728..3367dd95cf85da793da737c9630fe6659e232d31 100644 (file)
@@ -48,6 +48,8 @@ struct wpan_phy *wpan_phy_alloc(size_t priv_size);
 int wpan_phy_register(struct device *parent, struct wpan_phy *phy);
 void wpan_phy_unregister(struct wpan_phy *phy);
 void wpan_phy_free(struct wpan_phy *phy);
+/* Same semantics as for class_for_each_device */
+int wpan_phy_for_each(int (*fn)(struct wpan_phy *phy, void *data), void *data);
 
 static inline void *wpan_phy_priv(struct wpan_phy *phy)
 {
index f306604da67a747e792ffa318915530e97a5d45b..0cec138429162fc50e3bdb476d9da85b6c6e74ee 100644 (file)
@@ -91,6 +91,31 @@ struct wpan_phy *wpan_phy_find(const char *str)
 }
 EXPORT_SYMBOL(wpan_phy_find);
 
+struct wpan_phy_iter_data {
+       int (*fn)(struct wpan_phy *phy, void *data);
+       void *data;
+};
+
+static int wpan_phy_iter(struct device *dev, void *_data)
+{
+       struct wpan_phy_iter_data *wpid = _data;
+       struct wpan_phy *phy = container_of(dev, struct wpan_phy, dev);
+       return wpid->fn(phy, wpid->data);
+}
+
+int wpan_phy_for_each(int (*fn)(struct wpan_phy *phy, void *data),
+               void *data)
+{
+       struct wpan_phy_iter_data wpid = {
+               .fn = fn,
+               .data = data,
+       };
+
+       return class_for_each_device(&wpan_phy_class, NULL,
+                       &wpid, wpan_phy_iter);
+}
+EXPORT_SYMBOL(wpan_phy_for_each);
+
 static int wpan_phy_idx_valid(int idx)
 {
        return idx >= 0;