compress/octeontx: fix null pointer dereference

Message ID tencent_9FDC18169EAF53EA086C1D92EFFC112B9107@qq.com (mailing list archive)
State Superseded, archived
Headers
Series compress/octeontx: fix null pointer dereference |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK
ci/intel-Testing fail Testing issues

Commit Message

Weiguo Li Jan. 25, 2022, 2:22 p.m. UTC
  Check for memory allocation failure is added to avoid null
pointer dereference.

Signed-off-by: Weiguo Li <liwg06@foxmail.com>
---
 drivers/compress/octeontx/otx_zip_pmd.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
  

Patch

diff --git a/drivers/compress/octeontx/otx_zip_pmd.c b/drivers/compress/octeontx/otx_zip_pmd.c
index dd62285b86..be6f0d358f 100644
--- a/drivers/compress/octeontx/otx_zip_pmd.c
+++ b/drivers/compress/octeontx/otx_zip_pmd.c
@@ -392,6 +392,8 @@  zip_pmd_qp_setup(struct rte_compressdev *dev, uint16_t qp_id,
 	}
 
 	name =  rte_malloc(NULL, RTE_COMPRESSDEV_NAME_MAX_LEN, 0);
+	if (name == NULL)
+		return (-ENOMEM);
 	snprintf(name, RTE_COMPRESSDEV_NAME_MAX_LEN,
 		 "zip_pmd_%u_qp_%u",
 		 dev->data->dev_id, qp_id);
@@ -399,8 +401,11 @@  zip_pmd_qp_setup(struct rte_compressdev *dev, uint16_t qp_id,
 	/* Allocate the queue pair data structure. */
 	qp = rte_zmalloc_socket(name, sizeof(*qp),
 				RTE_CACHE_LINE_SIZE, socket_id);
-	if (qp == NULL)
+	if (qp == NULL) {
+		rte_free(name);
 		return (-ENOMEM);
+	}
+
 
 	qp->name = name;