[PATCH 4.19 194/639] RDMA/mlx5: Fix memory leak in case we fail to add an IB device

From: Greg Kroah-Hartman
Date: Fri Jan 24 2020 - 06:10:32 EST


From: Mark Bloch <markb@xxxxxxxxxxxx>

[ Upstream commit fc9e4477f924e84d7798f7a1d41401d699de1219 ]

Make sure the IB device is freed on failure.

Fixes: b5ca15ad7e61 ("IB/mlx5: Add proper representors support")
Signed-off-by: Mark Bloch <markb@xxxxxxxxxxxx>
Reviewed-by: Bodong Wang <bodong@xxxxxxxxxxxx>
Reviewed-by: HÃkon Bugge <haakon.bugge@xxxxxxxxxx>
Signed-off-by: Leon Romanovsky <leonro@xxxxxxxxxxxx>
Signed-off-by: Jason Gunthorpe <jgg@xxxxxxxxxxxx>
Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>
---
drivers/infiniband/hw/mlx5/ib_rep.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/infiniband/hw/mlx5/ib_rep.c b/drivers/infiniband/hw/mlx5/ib_rep.c
index 35a0e04c38f28..b841589c27c9c 100644
--- a/drivers/infiniband/hw/mlx5/ib_rep.c
+++ b/drivers/infiniband/hw/mlx5/ib_rep.c
@@ -69,8 +69,10 @@ mlx5_ib_vport_rep_load(struct mlx5_core_dev *dev, struct mlx5_eswitch_rep *rep)
ibdev->mdev = dev;
ibdev->num_ports = max(MLX5_CAP_GEN(dev, num_ports),
MLX5_CAP_GEN(dev, num_vhca_ports));
- if (!__mlx5_ib_add(ibdev, &rep_profile))
+ if (!__mlx5_ib_add(ibdev, &rep_profile)) {
+ ib_dealloc_device(&ibdev->ib_dev);
return -EINVAL;
+ }

rep->rep_if[REP_IB].priv = ibdev;

--
2.20.1