[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 08/11] tests/qtest: xlnx-canfd-test: Fix code coverity issues
From: |
Peter Maydell |
Subject: |
[PULL 08/11] tests/qtest: xlnx-canfd-test: Fix code coverity issues |
Date: |
Tue, 4 Jul 2023 17:36:31 +0100 |
From: Vikram Garhwal <vikram.garhwal@amd.com>
Following are done to fix the coverity issues:
1. Change read_data to fix the CID 1512899: Out-of-bounds access (OVERRUN)
2. Fix match_rx_tx_data to fix CID 1512900: Logically dead code (DEADCODE)
3. Replace rand() in generate_random_data() with g_rand_int()
Signed-off-by: Vikram Garhwal <vikram.garhwal@amd.com>
Message-id: 20230628202758.16398-1-vikram.garhwal@amd.com
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
tests/qtest/xlnx-canfd-test.c | 33 +++++++++++----------------------
1 file changed, 11 insertions(+), 22 deletions(-)
diff --git a/tests/qtest/xlnx-canfd-test.c b/tests/qtest/xlnx-canfd-test.c
index 76ee106d4f4..78ec9ef2a76 100644
--- a/tests/qtest/xlnx-canfd-test.c
+++ b/tests/qtest/xlnx-canfd-test.c
@@ -170,23 +170,23 @@ static void generate_random_data(uint32_t *buf_tx, bool
is_canfd_frame)
/* Generate random TX data for CANFD frame. */
if (is_canfd_frame) {
for (int i = 0; i < CANFD_FRAME_SIZE - 2; i++) {
- buf_tx[2 + i] = rand();
+ buf_tx[2 + i] = g_random_int();
}
} else {
/* Generate random TX data for CAN frame. */
for (int i = 0; i < CAN_FRAME_SIZE - 2; i++) {
- buf_tx[2 + i] = rand();
+ buf_tx[2 + i] = g_random_int();
}
}
}
-static void read_data(QTestState *qts, uint64_t can_base_addr, uint32_t
*buf_rx)
+static void read_data(QTestState *qts, uint64_t can_base_addr, uint32_t
*buf_rx,
+ uint32_t frame_size)
{
uint32_t int_status;
uint32_t fifo_status_reg_value;
/* At which RX FIFO the received data is stored. */
uint8_t store_ind = 0;
- bool is_canfd_frame = false;
/* Read the interrupt on CANFD rx. */
int_status = qtest_readl(qts, can_base_addr + R_ISR_OFFSET) & ISR_RXOK;
@@ -207,16 +207,9 @@ static void read_data(QTestState *qts, uint64_t
can_base_addr, uint32_t *buf_rx)
buf_rx[0] = qtest_readl(qts, can_base_addr + R_RX0_ID_OFFSET);
buf_rx[1] = qtest_readl(qts, can_base_addr + R_RX0_DLC_OFFSET);
- is_canfd_frame = (buf_rx[1] >> DLC_FD_BIT_SHIFT) & 1;
-
- if (is_canfd_frame) {
- for (int i = 0; i < CANFD_FRAME_SIZE - 2; i++) {
- buf_rx[i + 2] = qtest_readl(qts,
- can_base_addr + R_RX0_DATA1_OFFSET + 4 *
i);
- }
- } else {
- buf_rx[2] = qtest_readl(qts, can_base_addr + R_RX0_DATA1_OFFSET);
- buf_rx[3] = qtest_readl(qts, can_base_addr + R_RX0_DATA2_OFFSET);
+ for (int i = 0; i < frame_size - 2; i++) {
+ buf_rx[i + 2] = qtest_readl(qts,
+ can_base_addr + R_RX0_DATA1_OFFSET + 4 * i);
}
/* Clear the RX interrupt. */
@@ -272,10 +265,6 @@ static void match_rx_tx_data(const uint32_t *buf_tx, const
uint32_t *buf_rx,
g_assert_cmpint((buf_rx[size] & DLC_FD_BIT_MASK), ==,
(buf_tx[size] & DLC_FD_BIT_MASK));
} else {
- if (!is_canfd_frame && size == 4) {
- break;
- }
-
g_assert_cmpint(buf_rx[size], ==, buf_tx[size]);
}
@@ -318,7 +307,7 @@ static void test_can_data_transfer(void)
write_data(qts, CANFD0_BASE_ADDR, buf_tx, false);
send_data(qts, CANFD0_BASE_ADDR);
- read_data(qts, CANFD1_BASE_ADDR, buf_rx);
+ read_data(qts, CANFD1_BASE_ADDR, buf_rx, CAN_FRAME_SIZE);
match_rx_tx_data(buf_tx, buf_rx, false);
qtest_quit(qts);
@@ -358,7 +347,7 @@ static void test_canfd_data_transfer(void)
write_data(qts, CANFD0_BASE_ADDR, buf_tx, true);
send_data(qts, CANFD0_BASE_ADDR);
- read_data(qts, CANFD1_BASE_ADDR, buf_rx);
+ read_data(qts, CANFD1_BASE_ADDR, buf_rx, CANFD_FRAME_SIZE);
match_rx_tx_data(buf_tx, buf_rx, true);
qtest_quit(qts);
@@ -397,7 +386,7 @@ static void test_can_loopback(void)
write_data(qts, CANFD0_BASE_ADDR, buf_tx, true);
send_data(qts, CANFD0_BASE_ADDR);
- read_data(qts, CANFD0_BASE_ADDR, buf_rx);
+ read_data(qts, CANFD0_BASE_ADDR, buf_rx, CANFD_FRAME_SIZE);
match_rx_tx_data(buf_tx, buf_rx, true);
generate_random_data(buf_tx, true);
@@ -405,7 +394,7 @@ static void test_can_loopback(void)
write_data(qts, CANFD1_BASE_ADDR, buf_tx, true);
send_data(qts, CANFD1_BASE_ADDR);
- read_data(qts, CANFD1_BASE_ADDR, buf_rx);
+ read_data(qts, CANFD1_BASE_ADDR, buf_rx, CANFD_FRAME_SIZE);
match_rx_tx_data(buf_tx, buf_rx, true);
qtest_quit(qts);
--
2.34.1
- Re: [PULL 07/11] tests/tcg/aarch64: Add testcases for IC IVAU and dual-mapped code, (continued)
- Re: [PULL 07/11] tests/tcg/aarch64: Add testcases for IC IVAU and dual-mapped code, Philippe Mathieu-Daudé, 2023/07/05
- Re: [PULL 07/11] tests/tcg/aarch64: Add testcases for IC IVAU and dual-mapped code, Richard Henderson, 2023/07/05
- Re: [PULL 07/11] tests/tcg/aarch64: Add testcases for IC IVAU and dual-mapped code, Peter Maydell, 2023/07/06
- Re: [PULL 07/11] tests/tcg/aarch64: Add testcases for IC IVAU and dual-mapped code, John Högberg, 2023/07/06
- Re: [PULL 07/11] tests/tcg/aarch64: Add testcases for IC IVAU and dual-mapped code, Peter Maydell, 2023/07/06
- Re: [PULL 07/11] tests/tcg/aarch64: Add testcases for IC IVAU and dual-mapped code, John Högberg, 2023/07/07
[PULL 06/11] target/arm: Handle IC IVAU to improve compatibility with JITs, Peter Maydell, 2023/07/04
[PULL 03/11] target/arm: Avoid splitting Zregs across lines in dump, Peter Maydell, 2023/07/04
[PULL 02/11] hw/arm/sbsa-ref: use XHCI to replace EHCI, Peter Maydell, 2023/07/04
[PULL 04/11] target/arm: Dump ZA[] when active, Peter Maydell, 2023/07/04
[PULL 08/11] tests/qtest: xlnx-canfd-test: Fix code coverity issues,
Peter Maydell <=
[PULL 05/11] target/arm: Fix SME full tile indexing, Peter Maydell, 2023/07/04
[PULL 10/11] hw: arm: allwinner-sramc: Set class_size, Peter Maydell, 2023/07/04
[PULL 09/11] target/arm: gdbstub: Guard M-profile code with CONFIG_TCG, Peter Maydell, 2023/07/04
[PULL 11/11] target/xtensa: Assert that interrupt level is within bounds, Peter Maydell, 2023/07/04
Re: [PULL 00/11] target-arm queue, Richard Henderson, 2023/07/05