From: Rohit Raj <rohit.raj@nxp.com>
Free vfio_group_fd if add group fails to avoid ersource leak
NXP coverity-id: 26661846
Signed-off-by: Rohit Raj <rohit.raj@nxp.com>
---
drivers/bus/fslmc/fslmc_vfio.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
@@ -347,8 +347,10 @@ fslmc_vfio_open_group_fd(const char *group_name)
} else {
ret = fslmc_vfio_add_group(vfio_group_fd, iommu_group_num,
group_name);
- if (ret)
+ if (ret) {
+ close(vfio_group_fd);
return ret;
+ }
}
return vfio_group_fd;
@@ -1480,6 +1482,8 @@ fslmc_vfio_setup_group(void)
if (vfio_group_fd <= 0) {
vfio_group_fd = fslmc_vfio_open_group_fd(group_name);
if (vfio_group_fd <= 0) {
+ if (!vfio_group_fd)
+ close(vfio_group_fd);
DPAA2_BUS_ERR("Failed to create MC VFIO group");
return -rte_errno;
}