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

Ralph Siemsen ralph.siemsen at linaro.org
Wed Sep 9 03:33:25 CEST 2020


The bitflip test uses two equal sized memory buffers. This is achived
by splitting the range of memory into two pieces. The address of the
second buffer was not correctly calulated, thus the bitflip test would
accessing memory beyond the end of the specified range.

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 in
turn misses the last word.

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

Signed-off-by: Ralph Siemsen <ralph.siemsen at linaro.org>
--
TODO/FIXME: maybe the ending address should be automatically aligned?

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

diff --git a/cmd/mem.c b/cmd/mem.c
index 9b97f7bf69..88e15b2d61 100644
--- a/cmd/mem.c
+++ b/cmd/mem.c
@@ -988,8 +988,9 @@ static int do_mem_mtest(struct cmd_tbl *cmdtp, int flag, int argc,
 				break;
 			count += errs;
 			errs = test_bitflip_comparison(buf,
-						       buf + (end - start) / 2,
-						       (end - start) /
+						       buf + (end - start + 1) / 2 /
+						       sizeof(unsigned long),
+						       (end - start + 1) / 2 /
 						       sizeof(unsigned long));
 		} else {
 			errs = mem_test_quick(buf, start, end, pattern,
-- 
2.17.1



More information about the U-Boot mailing list