[Pdbg] [PATCH 5/5] libpdbg: Return immediate parent if class is NULL
Amitay Isaacs
amitay at ozlabs.org
Fri Sep 7 14:03:45 AEST 2018
On Fri, 2018-09-07 at 13:23 +1000, Alistair Popple wrote:
> Hi Amitay,
>
> What is this needed for? In the targetting model we have we are
> trying to avoid
> relying on overly specific parent/child relationships as they can be
> brittle,
> hence why callers need to specify which specific type/class of parent
> they are
> looking for. There's not much that could be done with an arbitrary
> parent
> anyway.
Well we need some mechanisms for traverseing the tree. I am re-using
this function to also do that. May be we need separate api when we are
just traversing the tree and when we are searching for targets based on
class.
I needed this functionality in testing to go up and down the device
tree from a node.
>
> Although I agree an `assert(class)` would probably assist debug.
>
> - Alistair
>
> On Thursday, 16 August 2018 3:57:56 PM AEST Amitay Isaacs wrote:
> > This avoids the segfault if class is NULL. Also, this api can be
> > used
> > to traverse the tree by explicitly setting class=NULL.
> >
> > Signed-off-by: Amitay Isaacs <amitay at ozlabs.org>
> > ---
> > libpdbg/libpdbg.c | 3 +++
> > 1 file changed, 3 insertions(+)
> >
> > diff --git a/libpdbg/libpdbg.c b/libpdbg/libpdbg.c
> > index 522bec9..810e045 100644
> > --- a/libpdbg/libpdbg.c
> > +++ b/libpdbg/libpdbg.c
> > @@ -89,6 +89,9 @@ struct pdbg_target *pdbg_target_parent(const char
> > *class, struct pdbg_target *ta
> > {
> > struct pdbg_target *parent;
> >
> > + if (!class)
> > + return target->parent;
> > +
> > for (parent = target->parent; parent && parent->parent; parent
> > = parent->parent) {
> > if (!strcmp(class, pdbg_target_class_name(parent)))
> > return parent;
> >
>
>
Amitay.
--
The cop already knows what a sysadmin has to learn: The best way to
manage a thousand users is at gunpoint. - Mike O'Connor on system security
More information about the Pdbg
mailing list