[8/9] dma/skeleton: fix segment fault when parse devargs

Message ID 20230302075012.32423-9-fengchengwen@huawei.com (mailing list archive)
State Accepted, archived
Delegated to: David Marchand
Headers
Series fix kvargs callback prototype not clearly defined |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

fengchengwen March 2, 2023, 7:50 a.m. UTC
  The rte_kvargs_process() was used to parse KV pairs, it also supports
to parse 'only keys' (e.g. socket_id) type. And the callback function
parameter 'value' is NULL when parsed 'only keys'.

This patch fixes segment fault when parse input args with 'only keys'
(e.g. lcore).

Fixes: 05d5fc66a269 ("dma/skeleton: introduce skeleton driver")
Cc: stable@dpdk.org

Signed-off-by: Chengwen Feng <fengchengwen@huawei.com>
---
 drivers/dma/skeleton/skeleton_dmadev.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
  

Patch

diff --git a/drivers/dma/skeleton/skeleton_dmadev.c b/drivers/dma/skeleton/skeleton_dmadev.c
index 9b6da655fd..daf35eccce 100644
--- a/drivers/dma/skeleton/skeleton_dmadev.c
+++ b/drivers/dma/skeleton/skeleton_dmadev.c
@@ -515,9 +515,15 @@  skeldma_parse_lcore(const char *key __rte_unused,
 		    const char *value,
 		    void *opaque)
 {
-	int lcore_id = atoi(value);
+	int lcore_id;
+
+	if (value == NULL || opaque == NULL)
+		return -EINVAL;
+
+	lcore_id = atoi(value);
 	if (lcore_id >= 0 && lcore_id < RTE_MAX_LCORE)
 		*(int *)opaque = lcore_id;
+
 	return 0;
 }