From c1cd44cab4dec3087f197a160529765502d176e8 Mon Sep 17 00:00:00 2001 From: Andrei Emeltchenko Date: Mon, 8 Mar 2021 11:17:17 +0200 Subject: [PATCH] tests: edac: Ensure vars are not changed in assert evaluation Coverity analysis reported following cases with side effect in assertion (ASSERT_SIDE_EFFECT): CID: 219574 CID: 219644 CID: 219659 Avoid issue by loading volatiles to local variables before assertion. Fixes: #33079 Fixes: #33042 Fixes: #33030 Signed-off-by: Andrei Emeltchenko --- tests/subsys/edac/ibecc/src/ibecc.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/tests/subsys/edac/ibecc/src/ibecc.c b/tests/subsys/edac/ibecc/src/ibecc.c index 23140a7628b..436ee44c90b 100644 --- a/tests/subsys/edac/ibecc/src/ibecc.c +++ b/tests/subsys/edac/ibecc/src/ibecc.c @@ -135,7 +135,7 @@ static void test_inject(uint64_t addr, uint64_t mask, uint8_t type) uint64_t test_addr; uint32_t test_value; - int ret; + int ret, num_int; interrupt = 0; @@ -173,12 +173,15 @@ static void test_inject(uint64_t addr, uint64_t mask, uint8_t type) /* Wait for interrupt if needed */ k_busy_wait(USEC_PER_MSEC * DURATION); - zassert_not_equal(interrupt, 0, "Interrupt handler did not execute"); - zassert_equal(interrupt, 1, - "Interrupt handler executed more than once! (%d)\n", - interrupt); + /* Load to local variable to avoid using volatile in assert */ + num_int = interrupt; - TC_PRINT("Interrupt %d\n", interrupt); + zassert_not_equal(num_int, 0, "Interrupt handler did not execute"); + zassert_equal(num_int, 1, + "Interrupt handler executed more than once! (%d)\n", + num_int); + + TC_PRINT("Interrupt %d\n", num_int); TC_PRINT("ECC Error Log 0x%llx\n", edac_ecc_error_log_get(dev)); TC_PRINT("Error: type %u, address 0x%llx, syndrome %u\n", error_type, error_address, error_syndrome); @@ -188,15 +191,20 @@ static int check_values(void *p1, void *p2, void *p3) { intptr_t address = (intptr_t)p1; intptr_t type = (intptr_t)p2; + intptr_t addr, errtype; #if defined(CONFIG_USERSPACE) TC_PRINT("Test communication in user mode thread\n"); zassert_true(_is_user_context(), "thread left in kernel mode"); #endif + /* Load to local variables to avoid using volatile in assert */ + addr = error_address; + errtype = error_type; + /* Verify page address and error type */ - zassert_equal(error_address, address, "Error address wrong"); - zassert_equal(error_type, type, "Error type wrong"); + zassert_equal(addr, address, "Error address wrong"); + zassert_equal(errtype, type, "Error type wrong"); return 0; }