Skip to content

Commit

Permalink
baseband/turbo_sw: fix memory leak in error path
Browse files Browse the repository at this point in the history
[ upstream commit 240fb56 ]

In q_setup() allocated memory for the queue data, we should free
it when error happens, otherwise it will lead to memory leak.

Fixes: b8cfe2c ("bb/turbo_sw: add software turbo driver")

Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>
Reviewed-by: Nicolas Chautru <nicolas.chautru@intel.com>
  • Loading branch information
wyjwang authored and bluca committed Nov 5, 2020
1 parent 145749b commit a973d06
Showing 1 changed file with 26 additions and 9 deletions.
35 changes: 26 additions & 9 deletions drivers/baseband/turbo_sw/bbdev_turbo_software.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <rte_ring.h>
#include <rte_kvargs.h>
#include <rte_cycles.h>
#include <rte_errno.h>

#include <rte_bbdev.h>
#include <rte_bbdev_pmd.h>
Expand Down Expand Up @@ -303,7 +304,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) *
Expand All @@ -312,6 +314,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;
}

Expand All @@ -323,14 +326,16 @@ 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),
RTE_CACHE_LINE_SIZE, queue_conf->socket);
if (q->enc_in == NULL) {
rte_bbdev_log(ERR,
"Failed to allocate queue memory for %s", name);
ret = -ENOMEM;
goto free_q;
}

Expand All @@ -341,14 +346,16 @@ 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),
RTE_CACHE_LINE_SIZE, queue_conf->socket);
if (q->ag == NULL) {
rte_bbdev_log(ERR,
"Failed to allocate queue memory for %s", name);
ret = -ENOMEM;
goto free_q;
}

Expand All @@ -359,14 +366,16 @@ 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),
RTE_CACHE_LINE_SIZE, queue_conf->socket);
if (q->code_block == NULL) {
rte_bbdev_log(ERR,
"Failed to allocate queue memory for %s", name);
ret = -ENOMEM;
goto free_q;
}

Expand All @@ -378,14 +387,16 @@ 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),
RTE_CACHE_LINE_SIZE, queue_conf->socket);
if (q->deint_input == NULL) {
rte_bbdev_log(ERR,
"Failed to allocate queue memory for %s", name);
ret = -ENOMEM;
goto free_q;
}

Expand All @@ -397,14 +408,16 @@ 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),
RTE_CACHE_LINE_SIZE, queue_conf->socket);
if (q->deint_output == NULL) {
rte_bbdev_log(ERR,
"Failed to allocate queue memory for %s", name);
ret = -ENOMEM;
goto free_q;
}

Expand All @@ -416,14 +429,16 @@ 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),
RTE_CACHE_LINE_SIZE, queue_conf->socket);
if (q->adapter_output == NULL) {
rte_bbdev_log(ERR,
"Failed to allocate queue memory for %s", name);
ret = -ENOMEM;
goto free_q;
}

Expand All @@ -434,12 +449,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;
}

Expand All @@ -459,7 +476,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 = {
Expand Down

0 comments on commit a973d06

Please sign in to comment.