diff options
author | Grant Likely <grant.likely@linaro.org> | 2014-05-21 12:04:17 -0400 |
---|---|---|
committer | Grant Likely <grant.likely@linaro.org> | 2014-05-22 22:25:27 -0400 |
commit | 0d0e02d605c5696a5076510f564fefe659127aa4 (patch) | |
tree | 90fa79bec74f545d261e315d63b6228d439a23e1 /drivers/of | |
parent | 11d200e95f3e84c1102e4cc9863a3614fd41f3ad (diff) |
of: Create unlocked version of for_each_child_of_node()
When iterating over nodes, sometimes it needs to be done when the DT
lock is already held. This patch makes an unlocked version of the
for_each_child_of_node() macro.
Signed-off-by: Grant Likely <grant.likely@linaro.org>
Diffstat (limited to 'drivers/of')
-rw-r--r-- | drivers/of/base.c | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/drivers/of/base.c b/drivers/of/base.c index 63ae00ec72ff..9df50c74162c 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c | |||
@@ -695,6 +695,22 @@ struct device_node *of_get_next_parent(struct device_node *node) | |||
695 | } | 695 | } |
696 | EXPORT_SYMBOL(of_get_next_parent); | 696 | EXPORT_SYMBOL(of_get_next_parent); |
697 | 697 | ||
698 | static struct device_node *__of_get_next_child(const struct device_node *node, | ||
699 | struct device_node *prev) | ||
700 | { | ||
701 | struct device_node *next; | ||
702 | |||
703 | next = prev ? prev->sibling : node->child; | ||
704 | for (; next; next = next->sibling) | ||
705 | if (of_node_get(next)) | ||
706 | break; | ||
707 | of_node_put(prev); | ||
708 | return next; | ||
709 | } | ||
710 | #define __for_each_child_of_node(parent, child) \ | ||
711 | for (child = __of_get_next_child(parent, NULL); child != NULL; \ | ||
712 | child = __of_get_next_child(parent, child)) | ||
713 | |||
698 | /** | 714 | /** |
699 | * of_get_next_child - Iterate a node childs | 715 | * of_get_next_child - Iterate a node childs |
700 | * @node: parent node | 716 | * @node: parent node |
@@ -710,11 +726,7 @@ struct device_node *of_get_next_child(const struct device_node *node, | |||
710 | unsigned long flags; | 726 | unsigned long flags; |
711 | 727 | ||
712 | raw_spin_lock_irqsave(&devtree_lock, flags); | 728 | raw_spin_lock_irqsave(&devtree_lock, flags); |
713 | next = prev ? prev->sibling : node->child; | 729 | next = __of_get_next_child(node, prev); |
714 | for (; next; next = next->sibling) | ||
715 | if (of_node_get(next)) | ||
716 | break; | ||
717 | of_node_put(prev); | ||
718 | raw_spin_unlock_irqrestore(&devtree_lock, flags); | 730 | raw_spin_unlock_irqrestore(&devtree_lock, flags); |
719 | return next; | 731 | return next; |
720 | } | 732 | } |