@@ -1249,6 +1249,7 @@ int of_phandle_iterator_init(struct of_phandle_iterator *it,
{
const __be32 *list;
int size;
+ struct device_node *walk;
memset(it, 0, sizeof(*it));
@@ -1270,6 +1271,16 @@ int of_phandle_iterator_init(struct of_phandle_iterator *it,
it->phandle_end = list;
it->cur = list;
+ /*
+ * find the root of our tree and record it, if we're dealing with an
+ * detached oftree - in non-detached case, we record NULL, for clear
+ * distinction between these two cases.
+ */
+ for (walk=(struct device_node*)np;
+ walk->parent;
+ walk=(struct device_node*)walk->parent);
+ it->root = ((walk == of_root) ? NULL : walk);
+
return 0;
}
EXPORT_SYMBOL_GPL(of_phandle_iterator_init);
@@ -1297,7 +1308,7 @@ int of_phandle_iterator_next(struct of_phandle_iterator *it)
* Find the provider node and parse the #*-cells property to
* determine the argument length.
*/
- it->node = of_find_node_by_phandle(it->phandle);
+ it->node = of_find_node_by_phandle_from(it->root, it->phandle);
if (it->cells_name) {
if (!it->node) {
@@ -82,6 +82,7 @@ struct of_phandle_iterator {
const char *cells_name;
int cell_count;
const struct device_node *parent;
+ struct device_node *root;
/* List size information */
const __be32 *list_end;
For detached oftree support, find the root node and record it, on iterator creation. If we find the root of the global oftree, record NULL, in order to have a clear distinction between detached and non-detached cases. The recorded root node is then used for resolving phandles. Note that in the detached case, phandle cache can't be used, so we have a little performance penalty on repeated phandle lookups. Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net> --- drivers/of/base.c | 13 ++++++++++++- include/linux/of.h | 1 + 2 files changed, 13 insertions(+), 1 deletion(-)