[Pdbg] [PATCH 08/23] libpdbg: Child traversal should not include virtual nodes
Amitay Isaacs
amitay at ozlabs.org
Thu Sep 19 12:33:18 AEST 2019
When traversing system device tree view (virtual = true), the children
are calculated based on the system device tree view (using the virtual
node attachments).
When traversing backend device tree (virtual = false), the virtual nodes
are ignored except if they are part of the backend device tree itself.
Signed-off-by: Amitay Isaacs <amitay at ozlabs.org>
---
libpdbg/libpdbg.c | 52 +++++++++++++++++++++++++++++++++++++++++------
libpdbg/libpdbg.h | 6 +++---
2 files changed, 49 insertions(+), 9 deletions(-)
diff --git a/libpdbg/libpdbg.c b/libpdbg/libpdbg.c
index aade5d3..b17853d 100644
--- a/libpdbg/libpdbg.c
+++ b/libpdbg/libpdbg.c
@@ -43,18 +43,58 @@ retry:
}
}
-struct pdbg_target *__pdbg_next_child_target(struct pdbg_target *parent, struct pdbg_target *last)
+static struct pdbg_target *pdbg_next_target_match(struct pdbg_target *next, bool virtual)
{
- if (!parent || list_empty(&parent->children))
+ if (virtual) {
+ if (!next->vnode)
+ return next;
+ else
+ if (!next->compatible)
+ return next->vnode;
+ } else {
+ if (next->compatible)
+ return next;
+ }
+
+ return NULL;
+}
+
+struct pdbg_target *__pdbg_next_child_target(struct pdbg_target *parent, struct pdbg_target *last, bool virtual)
+{
+ struct pdbg_target *next, *child = NULL;
+
+ if (!parent)
return NULL;
- if (!last)
- return list_top(&parent->children, struct pdbg_target, list);
+ if (list_empty(&parent->children)) {
+ if (parent->vnode)
+ parent = parent->vnode;
+ else
+ return NULL;
+ }
+
+ if (!last) {
+ list_for_each(&parent->children, child, list)
+ if ((next = pdbg_next_target_match(child, virtual)))
+ return next;
+
+ return NULL;
+ }
+
+ if (virtual && last->vnode && last->compatible)
+ last = last->vnode;
- if (last->list.next == &parent->children.n)
+ if (last == list_tail(&parent->children, struct pdbg_target, list))
return NULL;
- return list_entry(last->list.next, struct pdbg_target, list);
+ child = last;
+ do {
+ child = list_entry(child->list.next, struct pdbg_target, list);
+ if ((next = pdbg_next_target_match(child, virtual)))
+ return next;
+ } while (child != list_tail(&parent->children, struct pdbg_target, list));
+
+ return NULL;
}
enum pdbg_target_status pdbg_target_status(struct pdbg_target *target)
diff --git a/libpdbg/libpdbg.h b/libpdbg/libpdbg.h
index caf8b85..df74e43 100644
--- a/libpdbg/libpdbg.h
+++ b/libpdbg/libpdbg.h
@@ -20,7 +20,7 @@ struct pdbg_target *__pdbg_next_compatible_node(struct pdbg_target *root,
struct pdbg_target *prev,
const char *compat);
struct pdbg_target *__pdbg_next_target(const char *klass, struct pdbg_target *parent, struct pdbg_target *last);
-struct pdbg_target *__pdbg_next_child_target(struct pdbg_target *parent, struct pdbg_target *last);
+struct pdbg_target *__pdbg_next_child_target(struct pdbg_target *parent, struct pdbg_target *last, bool virtual);
/*
* Each target has a status associated with it. This is what each status means:
@@ -71,9 +71,9 @@ enum pdbg_backend { PDBG_DEFAULT_BACKEND = 0, PDBG_BACKEND_FSI, PDBG_BACKEND_I2C
target = __pdbg_next_target(class, NULL, target))
#define pdbg_for_each_child_target(parent, target) \
- for (target = __pdbg_next_child_target(parent, NULL); \
+ for (target = __pdbg_next_child_target(parent, NULL, true); \
target; \
- target = __pdbg_next_child_target(parent, target))
+ target = __pdbg_next_child_target(parent, target, true))
/* Return the first parent target of the given class, or NULL if the given
* target does not have a parent of the given class. */
--
2.21.0
More information about the Pdbg
mailing list