diff mbox series

libpdbg: Fix rework target addressing

Message ID 20181110100526.18403-1-npiggin@gmail.com
State Not Applicable
Headers show
Series libpdbg: Fix rework target addressing | expand

Commit Message

Nicholas Piggin Nov. 10, 2018, 10:05 a.m. UTC
Commit 936dbdcedb27 ("libpdbg: Rework target addressing") introduced
a bug in the target address calculation, using index 1 rather than the
intended 0.

Fixes: 936dbdcedb27 ("libpdbg: Rework target addressing")
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
---
 libpdbg/device.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

Comments

Alistair Popple Nov. 12, 2018, 6:57 a.m. UTC | #1
Thanks Nick!

We actually posted a fix for that bug on Friday though - see http://
patchwork.ozlabs.org/patch/995275/. I should probably have just pushed it out 
then. I've taken that patch over yours because it adds a test to catch when we 
break it again :-)

- Alistair

On Saturday, 10 November 2018 8:05:26 PM AEDT Nicholas Piggin wrote:
> Commit 936dbdcedb27 ("libpdbg: Rework target addressing") introduced
> a bug in the target address calculation, using index 1 rather than the
> intended 0.
> 
> Fixes: 936dbdcedb27 ("libpdbg: Rework target addressing")
> Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
> ---
>  libpdbg/device.c | 9 ++++-----
>  1 file changed, 4 insertions(+), 5 deletions(-)
> 
> diff --git a/libpdbg/device.c b/libpdbg/device.c
> index 9557172..f81b1b5 100644
> --- a/libpdbg/device.c
> +++ b/libpdbg/device.c
> @@ -626,15 +626,14 @@ uint64_t pdbg_target_address(struct pdbg_target
> *target, uint64_t *out_size) const struct dt_property *p;
>  	u32 na = dt_n_address_cells(target);
>  	u32 ns = dt_n_size_cells(target);
> -	u32 pos, n;
> +	u32 n;
> 
>  	p = dt_require_property(target, "reg", -1);
>  	n = (na + ns) * sizeof(u32);
> -	pos = n;
> -	assert((pos + n) <= p->len);
> +	assert(n <= p->len);
>  	if (out_size)
> -		*out_size = dt_get_number(p->prop + pos + na * sizeof(u32), ns);
> -	return dt_get_number(p->prop + pos, na);
> +		*out_size = dt_get_number(p->prop + na * sizeof(u32), ns);
> +	return dt_get_number(p->prop, na);
>  }
> 
>  void pdbg_targets_init(void *fdt)
diff mbox series

Patch

diff --git a/libpdbg/device.c b/libpdbg/device.c
index 9557172..f81b1b5 100644
--- a/libpdbg/device.c
+++ b/libpdbg/device.c
@@ -626,15 +626,14 @@  uint64_t pdbg_target_address(struct pdbg_target *target, uint64_t *out_size)
 	const struct dt_property *p;
 	u32 na = dt_n_address_cells(target);
 	u32 ns = dt_n_size_cells(target);
-	u32 pos, n;
+	u32 n;
 
 	p = dt_require_property(target, "reg", -1);
 	n = (na + ns) * sizeof(u32);
-	pos = n;
-	assert((pos + n) <= p->len);
+	assert(n <= p->len);
 	if (out_size)
-		*out_size = dt_get_number(p->prop + pos + na * sizeof(u32), ns);
-	return dt_get_number(p->prop + pos, na);
+		*out_size = dt_get_number(p->prop + na * sizeof(u32), ns);
+	return dt_get_number(p->prop, na);
 }
 
 void pdbg_targets_init(void *fdt)