aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorStephen Warren <swarren@nvidia.com>2012-11-20 18:12:20 -0500
committerRob Herring <rob.herring@calxeda.com>2012-11-20 23:58:55 -0500
commit50c8af4cf98fd97d6779f244215154e4c89699c7 (patch)
tree9690d810d1eef4b5dc8a26824dc699bbb4d54f44 /include
parentbe193249b4178158c0f697cb452b2bbf0cb16361 (diff)
of: introduce for_each_matching_node_and_match()
The following pattern of code is tempting: for_each_matching_node(np, table) { match = of_match_node(table, np); However, this results in iterating over table twice; the second time inside of_match_node(). The implementation of for_each_matching_node() already found the match, so this is redundant. Invent new function of_find_matching_node_and_match() and macro for_each_matching_node_and_match() to remove the double iteration, thus transforming the above code to: for_each_matching_node_and_match(np, table, &match) Signed-off-by: Stephen Warren <swarren@nvidia.com> Signed-off-by: Rob Herring <rob.herring@calxeda.com>
Diffstat (limited to 'include')
-rw-r--r--include/linux/of.h15
1 files changed, 13 insertions, 2 deletions
diff --git a/include/linux/of.h b/include/linux/of.h
index ab1af0e14659..13e0aacb4d9f 100644
--- a/include/linux/of.h
+++ b/include/linux/of.h
@@ -179,11 +179,22 @@ extern struct device_node *of_find_compatible_node(struct device_node *from,
179#define for_each_compatible_node(dn, type, compatible) \ 179#define for_each_compatible_node(dn, type, compatible) \
180 for (dn = of_find_compatible_node(NULL, type, compatible); dn; \ 180 for (dn = of_find_compatible_node(NULL, type, compatible); dn; \
181 dn = of_find_compatible_node(dn, type, compatible)) 181 dn = of_find_compatible_node(dn, type, compatible))
182extern struct device_node *of_find_matching_node(struct device_node *from, 182extern struct device_node *of_find_matching_node_and_match(
183 const struct of_device_id *matches); 183 struct device_node *from,
184 const struct of_device_id *matches,
185 const struct of_device_id **match);
186static inline struct device_node *of_find_matching_node(
187 struct device_node *from,
188 const struct of_device_id *matches)
189{
190 return of_find_matching_node_and_match(from, matches, NULL);
191}
184#define for_each_matching_node(dn, matches) \ 192#define for_each_matching_node(dn, matches) \
185 for (dn = of_find_matching_node(NULL, matches); dn; \ 193 for (dn = of_find_matching_node(NULL, matches); dn; \
186 dn = of_find_matching_node(dn, matches)) 194 dn = of_find_matching_node(dn, matches))
195#define for_each_matching_node_and_match(dn, matches, match) \
196 for (dn = of_find_matching_node_and_match(NULL, matches, match); \
197 dn; dn = of_find_matching_node_and_match(dn, matches, match))
187extern struct device_node *of_find_node_by_path(const char *path); 198extern struct device_node *of_find_node_by_path(const char *path);
188extern struct device_node *of_find_node_by_phandle(phandle handle); 199extern struct device_node *of_find_node_by_phandle(phandle handle);
189extern struct device_node *of_get_parent(const struct device_node *node); 200extern struct device_node *of_get_parent(const struct device_node *node);