From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id E985C41E65; Fri, 10 Mar 2023 15:26:18 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id D3DF241143; Fri, 10 Mar 2023 15:26:16 +0100 (CET) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mails.dpdk.org (Postfix) with ESMTP id 15E7B40685 for ; Fri, 10 Mar 2023 15:26:13 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1678458373; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=W1VEVT0AydcjQoqJ2qVz3oI9dM0kT1TXe+TZer5zYU4=; b=Vn+jGQpg7B1B6j3P27MLpnfVQbotQ92X5NNE4DISTO8X0IccI2aTuOO3EV2KcrQvcQsDhX L0H9i5rp32D4ew0UYLDUVUzsiGGPldOT/lEC0uLODaUV5CtNFvdOGqn4OY/CVXn7h9fKCL BFsuv7N0cw4N7mZj/djPxwp6PagPNC4= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-513-rs-OUCGYMYiUQNxznNhKAw-1; Fri, 10 Mar 2023 09:26:09 -0500 X-MC-Unique: rs-OUCGYMYiUQNxznNhKAw-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A84F085A5B1; Fri, 10 Mar 2023 14:26:08 +0000 (UTC) Received: from dmarchan.redhat.com (unknown [10.45.224.63]) by smtp.corp.redhat.com (Postfix) with ESMTP id A4B334014EB9; Fri, 10 Mar 2023 14:26:07 +0000 (UTC) From: David Marchand To: dev@dpdk.org Cc: stable@dpdk.org, Sachin Saxena , Hemant Agrawal , Shreyansh Jain Subject: [PATCH 1/2] raw/skeleton: fix selftest Date: Fri, 10 Mar 2023 15:26:03 +0100 Message-Id: <20230310142604.2409586-1-david.marchand@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org ASan reported issues in this driver. rte_rawdev_obj_t context object points at a uint16_t. skeleton_rawdev_enqueue_bufs() and skeleton_rawdev_dequeue_bufs() were incorrectly casting to an int. The enqueue/dequeue selftest had a leak on the enqueued string and was wrong in passing a rte_rawdev_buf pointer array. Fix this by allocating buffers on the stack and check that returned string is the expected one. Bugzilla ID: 1175 Fixes: 61c592a8d035 ("raw/skeleton: introduce skeleton rawdev driver") Fixes: 55ca1b0f2151 ("raw/skeleton: add test cases") Cc: stable@dpdk.org Signed-off-by: David Marchand --- drivers/raw/skeleton/skeleton_rawdev.c | 4 +- drivers/raw/skeleton/skeleton_rawdev_test.c | 46 +++++++++------------ 2 files changed, 22 insertions(+), 28 deletions(-) diff --git a/drivers/raw/skeleton/skeleton_rawdev.c b/drivers/raw/skeleton/skeleton_rawdev.c index 53fe49f936..6e99d35536 100644 --- a/drivers/raw/skeleton/skeleton_rawdev.c +++ b/drivers/raw/skeleton/skeleton_rawdev.c @@ -428,7 +428,7 @@ static int skeleton_rawdev_enqueue_bufs(struct rte_rawdev *dev, * help in complex implementation which require more information than * just an integer - for example, a queue-pair. */ - q_id = *((int *)context); + q_id = *((uint16_t *)context); for (i = 0; i < count; i++) queue_buf[q_id].bufs[i] = buffers[i]->buf_addr; @@ -450,7 +450,7 @@ static int skeleton_rawdev_dequeue_bufs(struct rte_rawdev *dev, * help in complex implementation which require more information than * just an integer - for example, a queue-pair. */ - q_id = *((int *)context); + q_id = *((uint16_t *)context); for (i = 0; i < count; i++) buffers[i]->buf_addr = queue_buf[q_id].bufs[i]; diff --git a/drivers/raw/skeleton/skeleton_rawdev_test.c b/drivers/raw/skeleton/skeleton_rawdev_test.c index ca15c49990..b7a7f623aa 100644 --- a/drivers/raw/skeleton/skeleton_rawdev_test.c +++ b/drivers/raw/skeleton/skeleton_rawdev_test.c @@ -370,40 +370,34 @@ static int test_rawdev_enqdeq(void) { int ret; - unsigned int count = 1; uint16_t queue_id = 0; - struct rte_rawdev_buf buffers[1]; - struct rte_rawdev_buf *deq_buffers = NULL; - - buffers[0].buf_addr = malloc(strlen(TEST_DEV_NAME) + 3); - if (!buffers[0].buf_addr) - goto cleanup; - snprintf(buffers[0].buf_addr, strlen(TEST_DEV_NAME) + 2, "%s%d", + struct rte_rawdev_buf buffer; + struct rte_rawdev_buf *buffers[1]; + struct rte_rawdev_buf deq_buffer; + struct rte_rawdev_buf *deq_buffers[1]; + + buffers[0] = &buffer; + buffer.buf_addr = malloc(strlen(TEST_DEV_NAME) + 3); + if (!buffer.buf_addr) + return TEST_FAILED; + snprintf(buffer.buf_addr, strlen(TEST_DEV_NAME) + 2, "%s%d", TEST_DEV_NAME, 0); - ret = rte_rawdev_enqueue_buffers(test_dev_id, - (struct rte_rawdev_buf **)&buffers, - count, &queue_id); - RTE_TEST_ASSERT_EQUAL((unsigned int)ret, count, + ret = rte_rawdev_enqueue_buffers(test_dev_id, buffers, + RTE_DIM(buffers), &queue_id); + RTE_TEST_ASSERT_EQUAL((unsigned int)ret, RTE_DIM(buffers), "Unable to enqueue buffers"); - deq_buffers = malloc(sizeof(struct rte_rawdev_buf) * count); - if (!deq_buffers) - goto cleanup; - - ret = rte_rawdev_dequeue_buffers(test_dev_id, - (struct rte_rawdev_buf **)&deq_buffers, - count, &queue_id); - RTE_TEST_ASSERT_EQUAL((unsigned int)ret, count, + deq_buffers[0] = &deq_buffer; + ret = rte_rawdev_dequeue_buffers(test_dev_id, deq_buffers, + RTE_DIM(deq_buffers), &queue_id); + RTE_TEST_ASSERT_EQUAL((unsigned int)ret, RTE_DIM(buffers), "Unable to dequeue buffers"); + RTE_TEST_ASSERT_EQUAL(deq_buffers[0]->buf_addr, buffers[0]->buf_addr, + "Did not retrieve expected object"); - free(deq_buffers); - + free(buffer.buf_addr); return TEST_SUCCESS; -cleanup: - free(buffers[0].buf_addr); - - return TEST_FAILED; } static void skeldev_test_run(int (*setup)(void), -- 2.39.2