Message ID | 20200110034043.27936-1-alistair@popple.id.au |
---|---|
State | Accepted |
Headers | show |
Series | libpdbg.c: Fix address translation | expand |
Context | Check | Description |
---|---|---|
snowpatch_ozlabs/apply_patch | warning | Failed to apply on branch master (8b4611b5d8e7e2279fe4aa80c892fcfe10aa398d) |
snowpatch_ozlabs/apply_patch | fail | Failed to apply to any branch |
Minor nit-pick. Avoid splitting log messages. May be just cache the old address and log it in the end. Reviewed-by: Amitay Isaacs <amitay@ozlabs.org> On Fri, 2020-01-10 at 14:40 +1100, Alistair Popple wrote: > If a target provides a translation callback it's expected that the > callback will return the absolute bus address to be used for the > access. However the caller of this callback was continuing to apply > translations to this absoulte address resulting in incorrect > translations in some cases. Instead short-circuit the translation > process. > > Signed-off-by: Alistair Popple <alistair@popple.id.au> > --- > libpdbg/target.c | 11 ++++++++--- > 1 file changed, 8 insertions(+), 3 deletions(-) > > diff --git a/libpdbg/target.c b/libpdbg/target.c > index dcbee2f..46004ef 100644 > --- a/libpdbg/target.c > +++ b/libpdbg/target.c > @@ -19,12 +19,16 @@ struct list_head target_classes = > LIST_HEAD_INIT(target_classes); > static struct pdbg_target *get_class_target_addr(struct pdbg_target > *target, const char *name, uint64_t *addr) > { > /* Check class */ > + pdbg_log(PDBG_DEBUG, "Target addr 0x%" PRIx64, *addr); > while (strcmp(target->class, name)) { > - > - if (target->translate) > + if (target->translate) { > *addr = target->translate(target, *addr); > - else > + target = target_parent(name, target, false); > + assert(target); > + break; > + } else { > *addr += pdbg_target_address(target, NULL); > + } > > /* Keep walking the tree translating addresses */ > target = get_parent(target, false); > @@ -34,6 +38,7 @@ static struct pdbg_target > *get_class_target_addr(struct pdbg_target *target, con > assert(target != pdbg_target_root()); > } > > + pdbg_log(PDBG_DEBUG, " -> 0x%" PRIx64 "\n", *addr); > return target; > } > > -- > 2.20.1 > Amitay.
diff --git a/libpdbg/target.c b/libpdbg/target.c index dcbee2f..46004ef 100644 --- a/libpdbg/target.c +++ b/libpdbg/target.c @@ -19,12 +19,16 @@ struct list_head target_classes = LIST_HEAD_INIT(target_classes); static struct pdbg_target *get_class_target_addr(struct pdbg_target *target, const char *name, uint64_t *addr) { /* Check class */ + pdbg_log(PDBG_DEBUG, "Target addr 0x%" PRIx64, *addr); while (strcmp(target->class, name)) { - - if (target->translate) + if (target->translate) { *addr = target->translate(target, *addr); - else + target = target_parent(name, target, false); + assert(target); + break; + } else { *addr += pdbg_target_address(target, NULL); + } /* Keep walking the tree translating addresses */ target = get_parent(target, false); @@ -34,6 +38,7 @@ static struct pdbg_target *get_class_target_addr(struct pdbg_target *target, con assert(target != pdbg_target_root()); } + pdbg_log(PDBG_DEBUG, " -> 0x%" PRIx64 "\n", *addr); return target; }
If a target provides a translation callback it's expected that the callback will return the absolute bus address to be used for the access. However the caller of this callback was continuing to apply translations to this absoulte address resulting in incorrect translations in some cases. Instead short-circuit the translation process. Signed-off-by: Alistair Popple <alistair@popple.id.au> --- libpdbg/target.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)