diff mbox series

[2/2] IB/mlx5: Free mpi in mp_slave mode

Message ID 20190916064818.19823-3-leon@kernel.org (mailing list archive)
State Accepted
Delegated to: Jason Gunthorpe
Headers show
Series Two fixes for this merge window | expand

Commit Message

Leon Romanovsky Sept. 16, 2019, 6:48 a.m. UTC
From: Danit Goldberg <danitg@mellanox.com>

ib_add_slave_port() allocates a multiport struct but never frees it.
Don't leak memory, free the allocated mpi struct during driver unload.

Fixes: 32f69e4be269 ("{net, IB}/mlx5: Manage port association for multiport RoCE")
Signed-off-by: Danit Goldberg <danitg@mellanox.com>
---
 drivers/infiniband/hw/mlx5/main.c | 1 +
 1 file changed, 1 insertion(+)

--
2.20.1

Comments

Jason Gunthorpe Sept. 16, 2019, 5:23 p.m. UTC | #1
On Mon, Sep 16, 2019 at 09:48:18AM +0300, Leon Romanovsky wrote:
> From: Danit Goldberg <danitg@mellanox.com>
> 
> ib_add_slave_port() allocates a multiport struct but never frees it.
> Don't leak memory, free the allocated mpi struct during driver unload.
> 
> Fixes: 32f69e4be269 ("{net, IB}/mlx5: Manage port association for multiport RoCE")
> Signed-off-by: Danit Goldberg <danitg@mellanox.com>
>  drivers/infiniband/hw/mlx5/main.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/infiniband/hw/mlx5/main.c b/drivers/infiniband/hw/mlx5/main.c
> index 0569bcab02d4..14807ea8dc3f 100644
> +++ b/drivers/infiniband/hw/mlx5/main.c
> @@ -6959,6 +6959,7 @@ static void mlx5_ib_remove(struct mlx5_core_dev *mdev, void *context)
>  			mlx5_ib_unbind_slave_port(mpi->ibdev, mpi);
>  		list_del(&mpi->list);
>  		mutex_unlock(&mlx5_ib_multiport_mutex);
> +		kfree(mpi);
>  		return;
>  	}

Personally I think the way this code was written to try to share the
struct mlx5_interface between two completely different usages, with
totally different opaque structs is really obtuse. 

Two interfaces callback blocks for the two parallel uses would have
been cleaner and might have made this missing kfree clearer.

Jason
diff mbox series

Patch

diff --git a/drivers/infiniband/hw/mlx5/main.c b/drivers/infiniband/hw/mlx5/main.c
index 0569bcab02d4..14807ea8dc3f 100644
--- a/drivers/infiniband/hw/mlx5/main.c
+++ b/drivers/infiniband/hw/mlx5/main.c
@@ -6959,6 +6959,7 @@  static void mlx5_ib_remove(struct mlx5_core_dev *mdev, void *context)
 			mlx5_ib_unbind_slave_port(mpi->ibdev, mpi);
 		list_del(&mpi->list);
 		mutex_unlock(&mlx5_ib_multiport_mutex);
+		kfree(mpi);
 		return;
 	}