From patchwork Thu Oct 15 13:45:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yunjian Wang X-Patchwork-Id: 80926 X-Patchwork-Delegate: gakhil@marvell.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 14341A04DB; Thu, 15 Oct 2020 15:46:25 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id D7DE61E971; Thu, 15 Oct 2020 15:46:23 +0200 (CEST) Received: from huawei.com (szxga05-in.huawei.com [45.249.212.191]) by dpdk.org (Postfix) with ESMTP id 4039E1E96E; Thu, 15 Oct 2020 15:46:21 +0200 (CEST) Received: from DGGEMS413-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id DC3D9849D129581C30DA; Thu, 15 Oct 2020 21:46:16 +0800 (CST) Received: from localhost (10.174.187.156) by DGGEMS413-HUB.china.huawei.com (10.3.19.213) with Microsoft SMTP Server id 14.3.487.0; Thu, 15 Oct 2020 21:46:07 +0800 From: wangyunjian To: CC: , , , Yunjian Wang , Date: Thu, 15 Oct 2020 21:45:45 +0800 Message-ID: <1602769545-29456-1-git-send-email-wangyunjian@huawei.com> X-Mailer: git-send-email 1.9.5.msysgit.1 In-Reply-To: <1cad32e57c8081477a0f448b5b3d61711ef6b382.1602060933.git.wangyunjian@huawei.com> References: <1cad32e57c8081477a0f448b5b3d61711ef6b382.1602060933.git.wangyunjian@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.174.187.156] X-CFilter-Loop: Reflected Subject: [dpdk-dev] [PATCH v2] baseband/turbo_sw: fix memory leak in error path X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" From: Yunjian Wang In q_setup() allocated memory for the queue data, we should free it when error happens, otherwise it will lead to memory leak. Fixes: b8cfe2c9aed2 ("bb/turbo_sw: add software turbo driver") Cc: stable@dpdk.org Signed-off-by: Yunjian Wang Reviewed-by: Nicolas Chautru --- v2: fix code styles Chautru Nicolas --- .../baseband/turbo_sw/bbdev_turbo_software.c | 35 ++++++++++++++----- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/drivers/baseband/turbo_sw/bbdev_turbo_software.c b/drivers/baseband/turbo_sw/bbdev_turbo_software.c index a36099e91..aa7f12238 100644 --- a/drivers/baseband/turbo_sw/bbdev_turbo_software.c +++ b/drivers/baseband/turbo_sw/bbdev_turbo_software.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -302,7 +303,8 @@ q_setup(struct rte_bbdev *dev, uint16_t q_id, rte_bbdev_log(ERR, "Creating queue name for device %u queue %u failed", dev->data->dev_id, q_id); - return -ENAMETOOLONG; + ret = -ENAMETOOLONG; + goto free_q; } q->enc_out = rte_zmalloc_socket(name, ((RTE_BBDEV_TURBO_MAX_TB_SIZE >> 3) + 3) * @@ -311,6 +313,7 @@ q_setup(struct rte_bbdev *dev, uint16_t q_id, if (q->enc_out == NULL) { rte_bbdev_log(ERR, "Failed to allocate queue memory for %s", name); + ret = -ENOMEM; goto free_q; } @@ -322,7 +325,8 @@ q_setup(struct rte_bbdev *dev, uint16_t q_id, rte_bbdev_log(ERR, "Creating queue name for device %u queue %u failed", dev->data->dev_id, q_id); - return -ENAMETOOLONG; + ret = -ENAMETOOLONG; + goto free_q; } q->enc_in = rte_zmalloc_socket(name, (RTE_BBDEV_LDPC_MAX_CB_SIZE >> 3) * sizeof(*q->enc_in), @@ -330,6 +334,7 @@ q_setup(struct rte_bbdev *dev, uint16_t q_id, if (q->enc_in == NULL) { rte_bbdev_log(ERR, "Failed to allocate queue memory for %s", name); + ret = -ENOMEM; goto free_q; } @@ -340,7 +345,8 @@ q_setup(struct rte_bbdev *dev, uint16_t q_id, rte_bbdev_log(ERR, "Creating queue name for device %u queue %u failed", dev->data->dev_id, q_id); - return -ENAMETOOLONG; + ret = -ENAMETOOLONG; + goto free_q; } q->ag = rte_zmalloc_socket(name, RTE_BBDEV_TURBO_MAX_CB_SIZE * 10 * sizeof(*q->ag), @@ -348,6 +354,7 @@ q_setup(struct rte_bbdev *dev, uint16_t q_id, if (q->ag == NULL) { rte_bbdev_log(ERR, "Failed to allocate queue memory for %s", name); + ret = -ENOMEM; goto free_q; } @@ -358,7 +365,8 @@ q_setup(struct rte_bbdev *dev, uint16_t q_id, rte_bbdev_log(ERR, "Creating queue name for device %u queue %u failed", dev->data->dev_id, q_id); - return -ENAMETOOLONG; + ret = -ENAMETOOLONG; + goto free_q; } q->code_block = rte_zmalloc_socket(name, RTE_BBDEV_TURBO_MAX_CB_SIZE * sizeof(*q->code_block), @@ -366,6 +374,7 @@ q_setup(struct rte_bbdev *dev, uint16_t q_id, if (q->code_block == NULL) { rte_bbdev_log(ERR, "Failed to allocate queue memory for %s", name); + ret = -ENOMEM; goto free_q; } @@ -377,7 +386,8 @@ q_setup(struct rte_bbdev *dev, uint16_t q_id, rte_bbdev_log(ERR, "Creating queue name for device %u queue %u failed", dev->data->dev_id, q_id); - return -ENAMETOOLONG; + ret = -ENAMETOOLONG; + goto free_q; } q->deint_input = rte_zmalloc_socket(name, DEINT_INPUT_BUF_SIZE * sizeof(*q->deint_input), @@ -385,6 +395,7 @@ q_setup(struct rte_bbdev *dev, uint16_t q_id, if (q->deint_input == NULL) { rte_bbdev_log(ERR, "Failed to allocate queue memory for %s", name); + ret = -ENOMEM; goto free_q; } @@ -396,7 +407,8 @@ q_setup(struct rte_bbdev *dev, uint16_t q_id, rte_bbdev_log(ERR, "Creating queue name for device %u queue %u failed", dev->data->dev_id, q_id); - return -ENAMETOOLONG; + ret = -ENAMETOOLONG; + goto free_q; } q->deint_output = rte_zmalloc_socket(NULL, DEINT_OUTPUT_BUF_SIZE * sizeof(*q->deint_output), @@ -404,6 +416,7 @@ q_setup(struct rte_bbdev *dev, uint16_t q_id, if (q->deint_output == NULL) { rte_bbdev_log(ERR, "Failed to allocate queue memory for %s", name); + ret = -ENOMEM; goto free_q; } @@ -415,7 +428,8 @@ q_setup(struct rte_bbdev *dev, uint16_t q_id, rte_bbdev_log(ERR, "Creating queue name for device %u queue %u failed", dev->data->dev_id, q_id); - return -ENAMETOOLONG; + ret = -ENAMETOOLONG; + goto free_q; } q->adapter_output = rte_zmalloc_socket(NULL, ADAPTER_OUTPUT_BUF_SIZE * sizeof(*q->adapter_output), @@ -423,6 +437,7 @@ q_setup(struct rte_bbdev *dev, uint16_t q_id, if (q->adapter_output == NULL) { rte_bbdev_log(ERR, "Failed to allocate queue memory for %s", name); + ret = -ENOMEM; goto free_q; } @@ -433,12 +448,14 @@ q_setup(struct rte_bbdev *dev, uint16_t q_id, rte_bbdev_log(ERR, "Creating queue name for device %u queue %u failed", dev->data->dev_id, q_id); - return -ENAMETOOLONG; + ret = -ENAMETOOLONG; + goto free_q; } q->processed_pkts = rte_ring_create(name, queue_conf->queue_size, queue_conf->socket, RING_F_SP_ENQ | RING_F_SC_DEQ); if (q->processed_pkts == NULL) { rte_bbdev_log(ERR, "Failed to create ring for %s", name); + ret = -rte_errno; goto free_q; } @@ -458,7 +475,7 @@ q_setup(struct rte_bbdev *dev, uint16_t q_id, rte_free(q->deint_output); rte_free(q->adapter_output); rte_free(q); - return -EFAULT; + return ret; } static const struct rte_bbdev_ops pmd_ops = {