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

Ralph Siemsen ralph.siemsen at linaro.org
Wed Sep 9 15:02:01 CEST 2020


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 at 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(-)

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);
-- 
2.17.1



More information about the U-Boot mailing list