diff mbox series

RDMA/mlx4: Fix potential memory leak

Message ID 1636020852-3951757-1-git-send-email-jiasheng@iscas.ac.cn (mailing list archive)
State Rejected
Delegated to: Leon Romanovsky
Headers show
Series RDMA/mlx4: Fix potential memory leak | expand

Commit Message

Jiasheng Jiang Nov. 4, 2021, 10:14 a.m. UTC
In the error path, the dev->dev isn't released.
Therefore, it might be better to fix it to avoid
potential memory leak.

Fixes: 9376932 ("IB/mlx4_ib: Add support for user MR re-registration")
Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>
---
 drivers/infiniband/hw/mlx4/mr.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Leon Romanovsky Nov. 7, 2021, 7:40 a.m. UTC | #1
On Thu, Nov 04, 2021 at 10:14:12AM +0000, Jiasheng Jiang wrote:
> In the error path, the dev->dev isn't released.
> Therefore, it might be better to fix it to avoid
> potential memory leak.
> 
> Fixes: 9376932 ("IB/mlx4_ib: Add support for user MR re-registration")
> Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>
> ---
>  drivers/infiniband/hw/mlx4/mr.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

I don't understand about which release you are talking, but this patch
can't be right. You are supposed to call to "release_mpt_entry" only in
the error flows which after successful mlx4_mr_hw_get_mpt().

Thanks

> 
> diff --git a/drivers/infiniband/hw/mlx4/mr.c b/drivers/infiniband/hw/mlx4/mr.c
> index 50becc0..d8ae92e 100644
> --- a/drivers/infiniband/hw/mlx4/mr.c
> +++ b/drivers/infiniband/hw/mlx4/mr.c
> @@ -473,7 +473,7 @@ struct ib_mr *mlx4_ib_rereg_user_mr(struct ib_mr *mr, int flags, u64 start,
>  	 */
>  	err =  mlx4_mr_hw_get_mpt(dev->dev, &mmr->mmr, &pmpt_entry);
>  	if (err)
> -		return ERR_PTR(err);
> +		goto release_mpt_entry;
>  
>  	if (flags & IB_MR_REREG_PD) {
>  		err = mlx4_mr_hw_change_pd(dev->dev, *pmpt_entry,
> -- 
> 2.7.4
>
diff mbox series

Patch

diff --git a/drivers/infiniband/hw/mlx4/mr.c b/drivers/infiniband/hw/mlx4/mr.c
index 50becc0..d8ae92e 100644
--- a/drivers/infiniband/hw/mlx4/mr.c
+++ b/drivers/infiniband/hw/mlx4/mr.c
@@ -473,7 +473,7 @@  struct ib_mr *mlx4_ib_rereg_user_mr(struct ib_mr *mr, int flags, u64 start,
 	 */
 	err =  mlx4_mr_hw_get_mpt(dev->dev, &mmr->mmr, &pmpt_entry);
 	if (err)
-		return ERR_PTR(err);
+		goto release_mpt_entry;
 
 	if (flags & IB_MR_REREG_PD) {
 		err = mlx4_mr_hw_change_pd(dev->dev, *pmpt_entry,