diff mbox series

[v2] cmd: mem: fix range of bitflip test

Message ID 20200909130201.12885-1-ralph.siemsen@linaro.org
State New
Headers show
Series [v2] cmd: mem: fix range of bitflip test | expand

Commit Message

Ralph Siemsen Sept. 9, 2020, 1:02 p.m. UTC
The bitflip test uses two equal sized memory buffers. This is achieved
by splitting the range of memory into two pieces. The address of the
second buffer, as well as the length of each buffer, were not correctly
calculated. This caused bitflip test to access beyond the end of range.
This patch fixes the pointer arithmetic problem.

A second problem arises because u-boot "mtest" command expects the
ending address to be inclusive. When computing (end - start) this
results in missing 1 byte of the requested length. The bitflip test
expects a count rather than an "ending" address. Thus it fails to test
the last word of the requested range. Fixed by using (end - start + 1).

Fixes: 8e434cb705d463bc8cff935160e4fb4c77cb99ab ("cmd: mem: Add bitflip
memory test to alternate mtest")

Signed-off-by: Ralph Siemsen <ralph.siemsen@linaro.org>

--

Changes in v2:
- Minor refactor to reduce line length
- Spellcheck and cleanup commit message

Change-Id: Ie641d04e731fc5bc6a3bbef914bf7fad136cdc94
---
 cmd/mem.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

-- 
2.17.1

Comments

Stefan Roese Sept. 9, 2020, 1:35 p.m. UTC | #1
On 09.09.20 15:02, Ralph Siemsen wrote:
> The bitflip test uses two equal sized memory buffers. This is achieved

> by splitting the range of memory into two pieces. The address of the

> second buffer, as well as the length of each buffer, were not correctly

> calculated. This caused bitflip test to access beyond the end of range.

> This patch fixes the pointer arithmetic problem.

> 

> A second problem arises because u-boot "mtest" command expects the

> ending address to be inclusive. When computing (end - start) this

> results in missing 1 byte of the requested length. The bitflip test

> expects a count rather than an "ending" address. Thus it fails to test

> the last word of the requested range. Fixed by using (end - start + 1).

> 

> Fixes: 8e434cb705d463bc8cff935160e4fb4c77cb99ab ("cmd: mem: Add bitflip

> memory test to alternate mtest")

> 

> Signed-off-by: Ralph Siemsen <ralph.siemsen@linaro.org>


Reviewed-by: Stefan Roese <sr@denx.de>


Thanks,
Stefan

> --

> 

> Changes in v2:

> - Minor refactor to reduce line length

> - Spellcheck and cleanup commit message

> 

> Change-Id: Ie641d04e731fc5bc6a3bbef914bf7fad136cdc94

> ---

>   cmd/mem.c | 9 +++++----

>   1 file changed, 5 insertions(+), 4 deletions(-)

> 

> diff --git a/cmd/mem.c b/cmd/mem.c

> index 9b97f7bf69..7bfa93d2a0 100644

> --- a/cmd/mem.c

> +++ b/cmd/mem.c

> @@ -934,7 +934,7 @@ static ulong mem_test_quick(vu_long *buf, ulong start_addr, ulong end_addr,

>   static int do_mem_mtest(struct cmd_tbl *cmdtp, int flag, int argc,

>   			char *const argv[])

>   {

> -	ulong start, end;

> +	ulong start, end, half_size;

>   	vu_long scratch_space;

>   	vu_long *buf, *dummy = &scratch_space;

>   	ulong iteration_limit = 0;

> @@ -987,10 +987,11 @@ static int do_mem_mtest(struct cmd_tbl *cmdtp, int flag, int argc,

>   			if (errs == -1UL)

>   				break;

>   			count += errs;

> +			half_size = (end - start + 1) / 2 /

> +				    sizeof(unsigned long);

>   			errs = test_bitflip_comparison(buf,

> -						       buf + (end - start) / 2,

> -						       (end - start) /

> -						       sizeof(unsigned long));

> +						       buf + half_size,

> +						       half_size);

>   		} else {

>   			errs = mem_test_quick(buf, start, end, pattern,

>   					      iteration);

> 



Viele Grüße,
Stefan

-- 
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-51 Fax: (+49)-8142-66989-80 Email: sr@denx.de
diff mbox series

Patch

diff --git a/cmd/mem.c b/cmd/mem.c
index 9b97f7bf69..7bfa93d2a0 100644
--- a/cmd/mem.c
+++ b/cmd/mem.c
@@ -934,7 +934,7 @@  static ulong mem_test_quick(vu_long *buf, ulong start_addr, ulong end_addr,
 static int do_mem_mtest(struct cmd_tbl *cmdtp, int flag, int argc,
 			char *const argv[])
 {
-	ulong start, end;
+	ulong start, end, half_size;
 	vu_long scratch_space;
 	vu_long *buf, *dummy = &scratch_space;
 	ulong iteration_limit = 0;
@@ -987,10 +987,11 @@  static int do_mem_mtest(struct cmd_tbl *cmdtp, int flag, int argc,
 			if (errs == -1UL)
 				break;
 			count += errs;
+			half_size = (end - start + 1) / 2 /
+				    sizeof(unsigned long);
 			errs = test_bitflip_comparison(buf,
-						       buf + (end - start) / 2,
-						       (end - start) /
-						       sizeof(unsigned long));
+						       buf + half_size,
+						       half_size);
 		} else {
 			errs = mem_test_quick(buf, start, end, pattern,
 					      iteration);