bus/fslmc: fix memory leak and cleanup
Coverity issue: 268327
Fixes: 828d51d8fc
("bus/fslmc: refactor scan and probe functions")
Cc: stable@dpdk.org
Signed-off-by: Shreyansh Jain <shreyansh.jain@nxp.com>
Acked-by: Hemant Agrawal <hemant.agrawal@nxp.com>
This commit is contained in:
parent
fe33fe37fd
commit
58b7c9ceed
@ -569,38 +569,39 @@ fslmc_process_iodevices(struct rte_dpaa2_device *dev)
|
|||||||
static int
|
static int
|
||||||
fslmc_process_mcp(struct rte_dpaa2_device *dev)
|
fslmc_process_mcp(struct rte_dpaa2_device *dev)
|
||||||
{
|
{
|
||||||
|
int ret;
|
||||||
intptr_t v_addr;
|
intptr_t v_addr;
|
||||||
char *dev_name;
|
char *dev_name = NULL;
|
||||||
struct fsl_mc_io dpmng = {0};
|
struct fsl_mc_io dpmng = {0};
|
||||||
struct mc_version mc_ver_info = {0};
|
struct mc_version mc_ver_info = {0};
|
||||||
|
|
||||||
rte_mcp_ptr_list = malloc(sizeof(void *) * 1);
|
rte_mcp_ptr_list = malloc(sizeof(void *) * 1);
|
||||||
if (!rte_mcp_ptr_list) {
|
if (!rte_mcp_ptr_list) {
|
||||||
DPAA2_BUS_ERR("Unable to allocate MC portal memory");
|
DPAA2_BUS_ERR("Unable to allocate MC portal memory");
|
||||||
return -ENOMEM;
|
ret = -ENOMEM;
|
||||||
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
dev_name = strdup(dev->device.name);
|
dev_name = strdup(dev->device.name);
|
||||||
if (!dev_name) {
|
if (!dev_name) {
|
||||||
DPAA2_BUS_ERR("Unable to allocate MC device name memory");
|
DPAA2_BUS_ERR("Unable to allocate MC device name memory");
|
||||||
free(rte_mcp_ptr_list);
|
ret = -ENOMEM;
|
||||||
rte_mcp_ptr_list = NULL;
|
goto cleanup;
|
||||||
return -ENOMEM;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
v_addr = vfio_map_mcp_obj(&vfio_group, dev_name);
|
v_addr = vfio_map_mcp_obj(&vfio_group, dev_name);
|
||||||
if (v_addr == (intptr_t)MAP_FAILED) {
|
if (v_addr == (intptr_t)MAP_FAILED) {
|
||||||
DPAA2_BUS_ERR("Error mapping region (errno = %d)", errno);
|
DPAA2_BUS_ERR("Error mapping region (errno = %d)", errno);
|
||||||
free(rte_mcp_ptr_list);
|
ret = -1;
|
||||||
rte_mcp_ptr_list = NULL;
|
goto cleanup;
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* check the MC version compatibility */
|
/* check the MC version compatibility */
|
||||||
dpmng.regs = (void *)v_addr;
|
dpmng.regs = (void *)v_addr;
|
||||||
if (mc_get_version(&dpmng, CMD_PRI_LOW, &mc_ver_info)) {
|
if (mc_get_version(&dpmng, CMD_PRI_LOW, &mc_ver_info)) {
|
||||||
DPAA2_BUS_ERR("Unable to obtain MC version");
|
DPAA2_BUS_ERR("Unable to obtain MC version");
|
||||||
return -1;
|
ret = -1;
|
||||||
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((mc_ver_info.major != MC_VER_MAJOR) ||
|
if ((mc_ver_info.major != MC_VER_MAJOR) ||
|
||||||
@ -610,13 +611,24 @@ fslmc_process_mcp(struct rte_dpaa2_device *dev)
|
|||||||
MC_VER_MAJOR, MC_VER_MINOR,
|
MC_VER_MAJOR, MC_VER_MINOR,
|
||||||
mc_ver_info.major, mc_ver_info.minor,
|
mc_ver_info.major, mc_ver_info.minor,
|
||||||
mc_ver_info.revision);
|
mc_ver_info.revision);
|
||||||
free(rte_mcp_ptr_list);
|
ret = -1;
|
||||||
rte_mcp_ptr_list = NULL;
|
goto cleanup;
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
rte_mcp_ptr_list[0] = (void *)v_addr;
|
rte_mcp_ptr_list[0] = (void *)v_addr;
|
||||||
|
|
||||||
|
free(dev_name);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
cleanup:
|
||||||
|
if (dev_name)
|
||||||
|
free(dev_name);
|
||||||
|
|
||||||
|
if (rte_mcp_ptr_list) {
|
||||||
|
free(rte_mcp_ptr_list);
|
||||||
|
rte_mcp_ptr_list = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
Loading…
Reference in New Issue
Block a user