From: David Marchand <david.marchand@redhat.com>
To: dev@dpdk.org
Cc: stable@dpdk.org, Sachin Saxena <sachin.saxena@nxp.com>,
Hemant Agrawal <hemant.agrawal@nxp.com>,
Shreyansh Jain <shreyansh.jain@nxp.com>
Subject: [PATCH 1/2] raw/skeleton: fix selftest
Date: Fri, 10 Mar 2023 15:26:03 +0100 [thread overview]
Message-ID: <20230310142604.2409586-1-david.marchand@redhat.com> (raw)
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 <david.marchand@redhat.com>
---
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
next reply other threads:[~2023-03-10 14:26 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-10 14:26 David Marchand [this message]
2023-03-10 14:26 ` [PATCH 2/2] test: add rawdev to fast tests David Marchand
2023-03-16 8:27 ` Hemant Agrawal
2023-03-13 2:17 ` [PATCH 1/2] raw/skeleton: fix selftest Jiang, YuX
2023-03-14 8:39 ` David Marchand
2023-03-16 8:26 ` Hemant Agrawal
2023-03-16 12:51 ` David Marchand
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230310142604.2409586-1-david.marchand@redhat.com \
--to=david.marchand@redhat.com \
--cc=dev@dpdk.org \
--cc=hemant.agrawal@nxp.com \
--cc=sachin.saxena@nxp.com \
--cc=shreyansh.jain@nxp.com \
--cc=stable@dpdk.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).