From patchwork Thu Jul 6 13:25:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 699590 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp3311817wrs; Thu, 6 Jul 2023 06:26:03 -0700 (PDT) X-Google-Smtp-Source: APBJJlG24ewr/ATjN5CQMIEQoUv8Tw9UCzagjyu4wzwaTK5aucJ0F6ldIGJM2W2AdCtXm0l8FUuk X-Received: by 2002:a05:620a:290c:b0:765:55c9:4e02 with SMTP id m12-20020a05620a290c00b0076555c94e02mr2518202qkp.41.1688649963229; Thu, 06 Jul 2023 06:26:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688649963; cv=none; d=google.com; s=arc-20160816; b=jWStG/Uki0I7Tfv/zyPIXGTLp5vn9xJdXzCLTQaE7Zexge8KLsWR1BCH25HtWtdPCb csOSiqGX8WfqHoJDQrbSTiOvMGN7gYklUyQKbjAVj+RvHGPzxEgotHkjiqU4j8DrWsn2 S5chS201+F4+3yjwK+/DaZec9Ksrp4T0FWRIxKQmbbbYTA1RhQoSbuxYgGtEwnMYoHPQ U4AiIbdLRWxRJxsI3fu13pUMhPL3UJZQQjQLxe/CrxnUGOYvzC8Fb+lNqMMtqFrmtupW HF33JywYIiQZGDvtydy880p/Tn9G0cUDigO375oIoxFsxS3F+NP+7AeDy4ZfOY7FiWFr 87Pg== 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=bFDrUYhlTVi/QyetgXx/byg2+yO/22Hp9SjwoefyKLk=; b=WEC8JAYlPalu2+iz+PU9xN9AieU7jEmZQBZTOqD+Q8sQYMpAPAVDnicfyqAU5QNnmD 5OvqZ+p+COnBbkCD7RQWaQ5TCQb696+DB87Bs2bv4pnrXDQTNeaQaVZCZmy6Y9cKxgvD UQKrK555SHV6A3HBmUmjkSURKJ5m6YdSPMUOFo10RBcA22BFywRfyI2L3Cey1Zk74KIe tzqJEowHWr8ISmBKlW0W9/tiHWY/Ckn0F9moHzWBpQHdHZujH43Fgt9hQ3NnBoFWWDmL 8FhmooOtiQkAF9vglXF4Bm+j8misgFhiXaQbxiRDxS/8d2RbigVFjaej8eU5KFnNzo+R RH8A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=vQL2mmkt; 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 u6-20020ae9c006000000b00767327f00c9si1081103qkk.242.2023.07.06.06.26.03 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 06 Jul 2023 06:26:03 -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=vQL2mmkt; 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 1qHOzJ-0004qc-VY; Thu, 06 Jul 2023 09:25:38 -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 1qHOzF-0004n7-4t for qemu-devel@nongnu.org; Thu, 06 Jul 2023 09:25:34 -0400 Received: from mail-wm1-x32f.google.com ([2a00:1450:4864:20::32f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qHOz4-0000rz-HB for qemu-devel@nongnu.org; Thu, 06 Jul 2023 09:25:29 -0400 Received: by mail-wm1-x32f.google.com with SMTP id 5b1f17b1804b1-3fbca8935bfso7474075e9.3 for ; Thu, 06 Jul 2023 06:25:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688649917; x=1691241917; 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=vQL2mmkt0V9P85K07yJe+oAEm/uVBF0ilHYfXzS5msprzOnQIFCq7Kn9hKbxu5OfH0 oi5l8pZ7Z7LHb5LpgrkO6ZO2gOr9/nv+Z5k0WjnvR57isukE23F5kX4MNXvrE7XuvH6N HhIW+oxHm3Bh9pmX5givrrBG8FgnSW9DNJd1ttLC4dmYLw5N68+bpP2pSJhIPX9Rhia3 e8BNTo9KmVEanzJ4ZYIFrqpG2UE9SlkBa59Ik2nQSYfBrgXD4mYADn2gMb3vq5LP/TR2 FbxkNI0w7hCuBOOOPYy837NczgBB3r9SdLu85DHG+xln4ElxsYs8P3VCZRoG+h14QdJa ECHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688649917; x=1691241917; 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=OdQ+pq43FbheGghqhj6+UwLJaGb5s9JAbSKpYi+VIzS07ue8d/gY9vb5q1xTWNdMeo vOVMzr2r7BFy8ZfQl7nl8HhF3B0gfbcLebz/3RV8zzOh5cLaelJV+3rVXzMge6v6Wvof ufPcHPcIiZqUog94WiVXsBtgXXPogA+kIoIk91XCfzAQIDOjyYgF/qzMagrmCFaNXHY3 gniJsjnfa9ExRdbMXEeFG7QihPW/cdCCdAodo6yQDG4N5LVqbMzCneJ3/E5AVm8dtobM bngdUqI+uQX8wsgcTO4/YLEVygxrrq2vy/sfv9Bh8dQk5b0e6G/SrCPoSSznCrvJyS2U ioWA== X-Gm-Message-State: ABy/qLY6ZN69L2opyb5oUqPitNVAP8yIrG+M4R+q93K+viIBOtfXpmfb XmvJH8P6eG2wBgqSTBc53k3HZbExMsuwu8Pcj3w= X-Received: by 2002:a1c:ed14:0:b0:3fb:4149:b816 with SMTP id l20-20020a1ced14000000b003fb4149b816mr1409609wmh.8.1688649917730; Thu, 06 Jul 2023 06:25:17 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id s15-20020a5d510f000000b00304adbeeabbsm1856170wrt.99.2023.07.06.06.25.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Jul 2023 06:25:17 -0700 (PDT) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PULL 08/14] tests/qtest: xlnx-canfd-test: Fix code coverity issues Date: Thu, 6 Jul 2023 14:25:06 +0100 Message-Id: <20230706132512.3534397-9-peter.maydell@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230706132512.3534397-1-peter.maydell@linaro.org> References: <20230706132512.3534397-1-peter.maydell@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32f; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x32f.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);