13957890b9c6c7fa4c7b92da04a64dd8d9c423ae
[openwrt/svn-archive/archive.git] / target / linux / brcm63xx / patches-3.14 / 001-of-Create-unlocked-version-of-for_each_child_of_node.patch
1 From 0d0e02d605c5696a5076510f564fefe659127aa4 Mon Sep 17 00:00:00 2001
2 From: Grant Likely <grant.likely@linaro.org>
3 Date: Thu, 22 May 2014 01:04:17 +0900
4 Subject: [PATCH] of: Create unlocked version of for_each_child_of_node()
5
6 When iterating over nodes, sometimes it needs to be done when the DT
7 lock is already held. This patch makes an unlocked version of the
8 for_each_child_of_node() macro.
9
10 Signed-off-by: Grant Likely <grant.likely@linaro.org>
11 ---
12 drivers/of/base.c | 22 +++++++++++++++++-----
13 1 file changed, 17 insertions(+), 5 deletions(-)
14
15 --- a/drivers/of/base.c
16 +++ b/drivers/of/base.c
17 @@ -545,6 +545,22 @@ struct device_node *of_get_next_parent(s
18 }
19 EXPORT_SYMBOL(of_get_next_parent);
20
21 +static struct device_node *__of_get_next_child(const struct device_node *node,
22 + struct device_node *prev)
23 +{
24 + struct device_node *next;
25 +
26 + next = prev ? prev->sibling : node->child;
27 + for (; next; next = next->sibling)
28 + if (of_node_get(next))
29 + break;
30 + of_node_put(prev);
31 + return next;
32 +}
33 +#define __for_each_child_of_node(parent, child) \
34 + for (child = __of_get_next_child(parent, NULL); child != NULL; \
35 + child = __of_get_next_child(parent, child))
36 +
37 /**
38 * of_get_next_child - Iterate a node childs
39 * @node: parent node
40 @@ -560,11 +576,7 @@ struct device_node *of_get_next_child(co
41 unsigned long flags;
42
43 raw_spin_lock_irqsave(&devtree_lock, flags);
44 - next = prev ? prev->sibling : node->child;
45 - for (; next; next = next->sibling)
46 - if (of_node_get(next))
47 - break;
48 - of_node_put(prev);
49 + next = __of_get_next_child(node, prev);
50 raw_spin_unlock_irqrestore(&devtree_lock, flags);
51 return next;
52 }