summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2015-10-27 09:12:18 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2015-11-04 08:03:42 +0100
commit4ff9e28abc2e31dabde6d71503219b3e50d9f4e3 (patch)
tree0de3d1df48ed78fb79e9f65c9378c1093072f442
parent8f130c738e6a28f8427a6b9bff8830f216aaa7e4 (diff)
downloadbarebox-4ff9e28abc2e31dabde6d71503219b3e50d9f4e3.tar.gz
memtest: move error handling to end of function
Move error handling out of the test code to make the actual test better visible. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
-rw-r--r--common/memtest.c37
1 files changed, 17 insertions, 20 deletions
diff --git a/common/memtest.c b/common/memtest.c
index d0a0571..026fd0d 100644
--- a/common/memtest.c
+++ b/common/memtest.c
@@ -347,7 +347,7 @@ static int update_progress(resource_size_t offset)
int mem_test_moving_inversions(resource_size_t _start, resource_size_t _end)
{
- volatile resource_size_t *start, num_words, offset, temp, anti_pattern;
+ volatile resource_size_t *start, num_words, offset, pattern, expected;
int ret;
_start = ALIGN(_start, sizeof(resource_size_t));
@@ -389,17 +389,13 @@ int mem_test_moving_inversions(resource_size_t _start, resource_size_t _end)
if (ret)
return ret;
- temp = start[offset];
- if (temp != (offset + 1)) {
- printf("\n");
- mem_test_report_failure("read/write",
- (offset + 1),
- temp, &start[offset]);
- return -EIO;
- }
+ pattern = start[offset];
+ expected = offset + 1;
- anti_pattern = ~(offset + 1);
- start[offset] = anti_pattern;
+ if (pattern != expected)
+ goto mem_err;
+
+ start[offset] = ~start[offset];
}
/* Check each location for the inverted pattern and zero it */
@@ -408,16 +404,11 @@ int mem_test_moving_inversions(resource_size_t _start, resource_size_t _end)
if (ret)
return ret;
- anti_pattern = ~(offset + 1);
- temp = start[offset];
+ pattern = start[offset];
+ expected = ~(offset + 1);
- if (temp != anti_pattern) {
- printf("\n");
- mem_test_report_failure("read/write",
- anti_pattern,
- temp, &start[offset]);
- return -EIO;
- }
+ if (pattern != expected)
+ goto mem_err;
start[offset] = 0;
}
@@ -427,4 +418,10 @@ int mem_test_moving_inversions(resource_size_t _start, resource_size_t _end)
printf("\n");
return 0;
+
+mem_err:
+ printf("\n");
+ mem_test_report_failure("read/write", expected, pattern, &start[offset]);
+
+ return -EIO;
}