aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJessica Clarke <jrtc27@jrtc27.com>2024-09-12 20:12:05 +0100
committerAntonio Borneo <borneo.antonio@gmail.com>2024-09-15 09:22:44 +0000
commitfd7b66c5eb038185b72953821204ec9bb8ce49d1 (patch)
treea1cf87ba97372380065e5ca63eb43bd66def1358
parent63ca9670321c1c057ee32e9925826f9f8c836005 (diff)
downloadriscv-openocd-fd7b66c5eb038185b72953821204ec9bb8ce49d1.zip
riscv-openocd-fd7b66c5eb038185b72953821204ec9bb8ce49d1.tar.gz
riscv-openocd-fd7b66c5eb038185b72953821204ec9bb8ce49d1.tar.bz2
binarybuffer: Fix inverted return value in buf_cmp
This is the fast path for when there is a mismatch in the leading whole bytes, which means we should return true to indicate not equal like all the other cases here and in the surrounding functions. Otherwise we'll incorrectly report _buf1 == _buf2 if and only if there are mismatches in the leading whole bytes. This was introduced during the refactor and optimisation referenced below. The only in-tree caller of this is jtag_check_value_inner, which will just fail to catch some errors. However, downstream in riscv-openocd it gets used in the riscv target to determine whether an IR scan is needed to select the debug module, and with an IRLEN >= 8 this breaks resetting if the encoding for the DMI isn't all-ones in its leading whole bytes (to match BYPASS), since it will believe they are the same and not do an IR scan, failing (with "At least one TAP shouldn't be in BYPASS mode") in the subsequent DR scan due to the TAP still being recorded as having bypass set (and really having an instruction of either BYPASS or IDCODE). Fixes: e4ee891759b0 ("improve buf_cmp and buf_cmp_mask helpers") Change-Id: Ic4f7ed094429abc4c06a775eb847a8b3ddf2e2d6 Signed-off-by: Jessica Clarke <jrtc27@jrtc27.com> Reviewed-on: https://review.openocd.org/c/openocd/+/8489 Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-by: Evgeniy Naydanov <evgeniy.naydanov@syntacore.com> Reviewed-by: Tomas Vanek <vanekt@fbl.cz> Tested-by: jenkins
-rw-r--r--src/helper/binarybuffer.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/src/helper/binarybuffer.c b/src/helper/binarybuffer.c
index 423739a..c25383d 100644
--- a/src/helper/binarybuffer.c
+++ b/src/helper/binarybuffer.c
@@ -74,7 +74,7 @@ bool buf_cmp(const void *_buf1, const void *_buf2, unsigned size)
unsigned last = size / 8;
if (memcmp(_buf1, _buf2, last) != 0)
- return false;
+ return true;
unsigned trailing = size % 8;
if (!trailing)