From patchwork Tue Jul 4 16:36:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 698959 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp2364239wrs; Tue, 4 Jul 2023 09:37:19 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7H33G2MlCxgtymRl125/K9hHocO3TKXs1Lv1evktPseawTZ4YESf6eAsbEkGuRNhaygJJ8 X-Received: by 2002:a05:620a:4113:b0:765:59d8:d421 with SMTP id j19-20020a05620a411300b0076559d8d421mr17833697qko.1.1688488639041; Tue, 04 Jul 2023 09:37:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688488639; cv=none; d=google.com; s=arc-20160816; b=bKQEatxwkgXsXXbqZKLLskt7AMVx4sRsXc04DcQi6EtJXuf3qu9dwh8Fu1XrZsm84P 04uMqRhL8Uj+KgIk/HitWQpa+9Y3MLG5S+hByoAxaudECh2w/vt+nLAiiRwgtZIlQk9w iZQqVMhR2utnUUM/M8bQ35TaAzzLL6MzvcY7UONfyohsCE11mK+ZeOz8xRJMQg47hsDQ Dfb1tPTKZXeXPzE/RE/evIAjOXoaTv+D0pblCTE2etonXGFwRXHUQYf/kzpCfDGjter+ nYXEg81Cgmk4FCztfXemCyk5baWkIzIDDW74xT3D10EOqJRw2QDVKiTZXE+ZEBzjZqf6 j2qw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=eZRfw+Y+qoCHkLPcJJixub5r6MA4gHrUcY1/kPyyLV8=; fh=PnYt+qEB9tAfMKoqBm2xjKOFpYyFFGPudh5cVIoieJM=; b=w1pS3Cl+A4RrWMXHWEC+zwpC9qyaaPC+Nid9BvlSuYAh39cm7kP3a8CoRmLZBegj/n izWjSCS1k3ua3Yg3FysLc99BMyxS+oL/KGiDyQSitwIyRklB80qS4jfs18vF7ZLTVnOc ttGbP3EOnWETwW0mjJyU9dmnWNHnHPLcXeTzZ03EP/WTTvz+OxyANwYR9y3Kv5YWnOXe azH0sWh2UjLjH3qVLq0EE8dFsokK8WnPNDOecyvN7o9Gyn8pIrvi0+XSnsMirKv9ipMJ qVqUTsBuIE3WhfP0Ya2ICOFIhZ/9OMPqU+ZeGyG590y2N8kOCr6VyPHd3Wl5cSUOtXii aZXw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=SL8Nrpcw; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id w12-20020ac857cc000000b003bfb6e305ebsi13027574qta.8.2023.07.04.09.37.18 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 04 Jul 2023 09:37:19 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=SL8Nrpcw; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qGj1E-0001KC-Gx; Tue, 04 Jul 2023 12:36:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qGj1C-0001IG-SW for qemu-devel@nongnu.org; Tue, 04 Jul 2023 12:36:46 -0400 Received: from mail-wr1-x42a.google.com ([2a00:1450:4864:20::42a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qGj16-0001og-IW for qemu-devel@nongnu.org; Tue, 04 Jul 2023 12:36:46 -0400 Received: by mail-wr1-x42a.google.com with SMTP id ffacd0b85a97d-313e09a5b19so4920852f8f.0 for ; Tue, 04 Jul 2023 09:36:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688488599; x=1691080599; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=eZRfw+Y+qoCHkLPcJJixub5r6MA4gHrUcY1/kPyyLV8=; b=SL8Nrpcw5kNmqXkEYA6axmI+XtxoWUkl7qvZZDQ5XBUsVmZlTEXmbcXs8fZKIFFmzF ejSVO7dDT9M442Uk1Ln7WR2kBMNZq2Lmy3FdPOvBaSgwaoNjeHN4PnS0kU4DKnx0pgGo +eLRlfrBoWT2PC7YgmHUCOZNq587IAh9K2TwARDnh2JzwG/pV8AzsMpT2RcwNzvziyUx oE5CmQXjfRH48zqxtWtBMMsb/yhIlCYg2ZAOz5tp2uKKZY3JSnk+pVcenwQXQMjT8Q+Y RNc7lVCtReZwUlPvEcUv1br5BpmY871zZyk6lyTHZzBPEKdSpAoMVEMxWElUdsgXlVXn /qOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688488599; x=1691080599; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=eZRfw+Y+qoCHkLPcJJixub5r6MA4gHrUcY1/kPyyLV8=; b=dfD1xpDQ04djsFRet3EIrW+rnUKR3L8bj3dXvlJ7+ebYSf4UnJXNLIDsybgdgY17rz QSnxoo39XgP/+c0QrMEA+WKljfyX+A0h2CyIg+MX9AgUQ7u3jql3P0v2Z6LP2Gs2y3dA lBfZtTNiKNEKJxcHHmfd9k2a1td/84reUS6Q+f7T53B0tw28IeNN1GcSNR5gPKVfLHVu hGcgss8BRa+M+/ReZX98yYd35eBNxPncMTlXb27l5aDdVy6DdMaGUrRvIt6gDGJdbX+V mxPRs/6k5uOWrF1hUjs0RbmnOE3ubm/LpYNU3Hjnr8FqvOu89e5u3ODniDP+Xq6xilBk HqdA== X-Gm-Message-State: AC+VfDwA5YdfsMADilC6f1/Gm04IZ+JIAaQH0kH6KeO8RyxcBKtCnPTU UXzSZ8C0bF2+KQTI75sgcHKislTnq7g4cjhSP1I= X-Received: by 2002:a5d:6308:0:b0:30f:c050:88dd with SMTP id i8-20020a5d6308000000b0030fc05088ddmr16419155wru.8.1688488599139; Tue, 04 Jul 2023 09:36:39 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id r8-20020a056000014800b003143b032b7asm4354258wrx.116.2023.07.04.09.36.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Jul 2023 09:36:38 -0700 (PDT) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PULL 08/11] tests/qtest: xlnx-canfd-test: Fix code coverity issues Date: Tue, 4 Jul 2023 17:36:31 +0100 Message-Id: <20230704163634.3188465-9-peter.maydell@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230704163634.3188465-1-peter.maydell@linaro.org> References: <20230704163634.3188465-1-peter.maydell@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42a; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x42a.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Vikram Garhwal 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 Message-id: 20230628202758.16398-1-vikram.garhwal@amd.com Reviewed-by: Peter Maydell Signed-off-by: Peter Maydell --- 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);