diff options
author | Joerg Roedel <jroedel@suse.de> | 2016-04-04 11:49:20 -0400 |
---|---|---|
committer | Rob Herring <robh@kernel.org> | 2016-04-19 18:25:14 -0400 |
commit | f623ce95a51baee6a6638f0b025efc0229a9ac0d (patch) | |
tree | a54f340319d4a3b5968263367da290c1a396b9f8 | |
parent | 2021bd01ffccf2728a591070008d7de5bc41306a (diff) |
of: Introduce of_for_each_phandle() helper macro
With this macro any user can easily iterate over a list of
phandles. The patch also converts __of_parse_phandle_with_args()
to make use of the macro.
The of_count_phandle_with_args() function is not converted,
because the macro hides the return value of of_phandle_iterator_init(),
which is needed in there.
Signed-off-by: Joerg Roedel <jroedel@suse.de>
Signed-off-by: Rob Herring <robh@kernel.org>
-rw-r--r-- | drivers/of/base.c | 7 | ||||
-rw-r--r-- | include/linux/of.h | 6 |
2 files changed, 7 insertions, 6 deletions
diff --git a/drivers/of/base.c b/drivers/of/base.c index fcff2b62ec10..ea5a13d3c5a5 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c | |||
@@ -1543,13 +1543,8 @@ static int __of_parse_phandle_with_args(const struct device_node *np, | |||
1543 | struct of_phandle_iterator it; | 1543 | struct of_phandle_iterator it; |
1544 | int rc, cur_index = 0; | 1544 | int rc, cur_index = 0; |
1545 | 1545 | ||
1546 | rc = of_phandle_iterator_init(&it, np, list_name, | ||
1547 | cells_name, cell_count); | ||
1548 | if (rc) | ||
1549 | return rc; | ||
1550 | |||
1551 | /* Loop over the phandles until all the requested entry is found */ | 1546 | /* Loop over the phandles until all the requested entry is found */ |
1552 | while ((rc = of_phandle_iterator_next(&it)) == 0) { | 1547 | of_for_each_phandle(&it, rc, np, list_name, cells_name, cell_count) { |
1553 | /* | 1548 | /* |
1554 | * All of the error cases bail out of the loop, so at | 1549 | * All of the error cases bail out of the loop, so at |
1555 | * this point, the parsing is successful. If the requested | 1550 | * this point, the parsing is successful. If the requested |
diff --git a/include/linux/of.h b/include/linux/of.h index 1f5e108f6716..b0b80716fbfb 100644 --- a/include/linux/of.h +++ b/include/linux/of.h | |||
@@ -908,6 +908,12 @@ static inline int of_property_read_s32(const struct device_node *np, | |||
908 | return of_property_read_u32(np, propname, (u32*) out_value); | 908 | return of_property_read_u32(np, propname, (u32*) out_value); |
909 | } | 909 | } |
910 | 910 | ||
911 | #define of_for_each_phandle(it, err, np, ln, cn, cc) \ | ||
912 | for (of_phandle_iterator_init((it), (np), (ln), (cn), (cc)), \ | ||
913 | err = of_phandle_iterator_next(it); \ | ||
914 | err == 0; \ | ||
915 | err = of_phandle_iterator_next(it)) | ||
916 | |||
911 | #define of_property_for_each_u32(np, propname, prop, p, u) \ | 917 | #define of_property_for_each_u32(np, propname, prop, p, u) \ |
912 | for (prop = of_find_property(np, propname, NULL), \ | 918 | for (prop = of_find_property(np, propname, NULL), \ |
913 | p = of_prop_next_u32(prop, NULL, &u); \ | 919 | p = of_prop_next_u32(prop, NULL, &u); \ |