提交 87ffea09 编写于 作者: A Andy Shevchenko 提交者: Rafael J. Wysocki

device property: Introduce fwnode_for_each_parent_node()

In a few cases the functionality of fwnode_for_each_parent_node()
is already in use. Introduce a common helper macro for it.

It may be used by others as well in the future.
Signed-off-by: NAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: NSakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: NRafael J. Wysocki <rafael.j.wysocki@intel.com>
上级 002752af
...@@ -596,17 +596,17 @@ EXPORT_SYMBOL_GPL(fwnode_get_next_parent); ...@@ -596,17 +596,17 @@ EXPORT_SYMBOL_GPL(fwnode_get_next_parent);
*/ */
struct device *fwnode_get_next_parent_dev(struct fwnode_handle *fwnode) struct device *fwnode_get_next_parent_dev(struct fwnode_handle *fwnode)
{ {
struct fwnode_handle *parent;
struct device *dev; struct device *dev;
fwnode_handle_get(fwnode); fwnode_for_each_parent_node(fwnode, parent) {
do {
fwnode = fwnode_get_next_parent(fwnode);
if (!fwnode)
return NULL;
dev = get_dev_from_fwnode(fwnode); dev = get_dev_from_fwnode(fwnode);
} while (!dev); if (dev) {
fwnode_handle_put(fwnode); fwnode_handle_put(parent);
return dev; return dev;
}
}
return NULL;
} }
/** /**
...@@ -617,13 +617,11 @@ struct device *fwnode_get_next_parent_dev(struct fwnode_handle *fwnode) ...@@ -617,13 +617,11 @@ struct device *fwnode_get_next_parent_dev(struct fwnode_handle *fwnode)
*/ */
unsigned int fwnode_count_parents(const struct fwnode_handle *fwnode) unsigned int fwnode_count_parents(const struct fwnode_handle *fwnode)
{ {
struct fwnode_handle *__fwnode; struct fwnode_handle *parent;
unsigned int count; unsigned int count = 0;
__fwnode = fwnode_get_parent(fwnode);
for (count = 0; __fwnode; count++) fwnode_for_each_parent_node(fwnode, parent)
__fwnode = fwnode_get_next_parent(__fwnode); count++;
return count; return count;
} }
...@@ -644,15 +642,16 @@ EXPORT_SYMBOL_GPL(fwnode_count_parents); ...@@ -644,15 +642,16 @@ EXPORT_SYMBOL_GPL(fwnode_count_parents);
struct fwnode_handle *fwnode_get_nth_parent(struct fwnode_handle *fwnode, struct fwnode_handle *fwnode_get_nth_parent(struct fwnode_handle *fwnode,
unsigned int depth) unsigned int depth)
{ {
fwnode_handle_get(fwnode); struct fwnode_handle *parent;
do { if (depth == 0)
if (depth-- == 0) return fwnode_handle_get(fwnode);
break;
fwnode = fwnode_get_next_parent(fwnode);
} while (fwnode);
return fwnode; fwnode_for_each_parent_node(fwnode, parent) {
if (--depth == 0)
return parent;
}
return NULL;
} }
EXPORT_SYMBOL_GPL(fwnode_get_nth_parent); EXPORT_SYMBOL_GPL(fwnode_get_nth_parent);
...@@ -669,17 +668,20 @@ EXPORT_SYMBOL_GPL(fwnode_get_nth_parent); ...@@ -669,17 +668,20 @@ EXPORT_SYMBOL_GPL(fwnode_get_nth_parent);
bool fwnode_is_ancestor_of(struct fwnode_handle *test_ancestor, bool fwnode_is_ancestor_of(struct fwnode_handle *test_ancestor,
struct fwnode_handle *test_child) struct fwnode_handle *test_child)
{ {
struct fwnode_handle *parent;
if (IS_ERR_OR_NULL(test_ancestor)) if (IS_ERR_OR_NULL(test_ancestor))
return false; return false;
fwnode_handle_get(test_child); if (test_child == test_ancestor)
do {
if (test_child == test_ancestor) {
fwnode_handle_put(test_child);
return true; return true;
fwnode_for_each_parent_node(test_child, parent) {
if (parent == test_ancestor) {
fwnode_handle_put(parent);
return true;
}
} }
test_child = fwnode_get_next_parent(test_child);
} while (test_child);
return false; return false;
} }
......
...@@ -83,9 +83,14 @@ struct fwnode_handle *fwnode_find_reference(const struct fwnode_handle *fwnode, ...@@ -83,9 +83,14 @@ struct fwnode_handle *fwnode_find_reference(const struct fwnode_handle *fwnode,
const char *fwnode_get_name(const struct fwnode_handle *fwnode); const char *fwnode_get_name(const struct fwnode_handle *fwnode);
const char *fwnode_get_name_prefix(const struct fwnode_handle *fwnode); const char *fwnode_get_name_prefix(const struct fwnode_handle *fwnode);
struct fwnode_handle *fwnode_get_parent(const struct fwnode_handle *fwnode); struct fwnode_handle *fwnode_get_parent(const struct fwnode_handle *fwnode);
struct fwnode_handle *fwnode_get_next_parent( struct fwnode_handle *fwnode_get_next_parent(struct fwnode_handle *fwnode);
struct fwnode_handle *fwnode);
#define fwnode_for_each_parent_node(fwnode, parent) \
for (parent = fwnode_get_parent(fwnode); parent; \
parent = fwnode_get_next_parent(parent))
struct device *fwnode_get_next_parent_dev(struct fwnode_handle *fwnode); struct device *fwnode_get_next_parent_dev(struct fwnode_handle *fwnode);
unsigned int fwnode_count_parents(const struct fwnode_handle *fwn); unsigned int fwnode_count_parents(const struct fwnode_handle *fwn);
struct fwnode_handle *fwnode_get_nth_parent(struct fwnode_handle *fwn, struct fwnode_handle *fwnode_get_nth_parent(struct fwnode_handle *fwn,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册