diff mbox series

RDMA/erdma: Fix refcount leak in erdma_mmap

Message ID 20221220121139.1540564-1-linmq006@gmail.com (mailing list archive)
State Accepted
Headers show
Series RDMA/erdma: Fix refcount leak in erdma_mmap | expand

Commit Message

Miaoqian Lin Dec. 20, 2022, 12:11 p.m. UTC
rdma_user_mmap_entry_get() take reference, we should release it when not
need anymore, add the missing rdma_user_mmap_entry_put() in the error
path to fix it.

Fixes: 155055771704 ("RDMA/erdma: Add verbs implementation")
Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
---
 drivers/infiniband/hw/erdma/erdma_verbs.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Cheng Xu Dec. 21, 2022, 2:58 a.m. UTC | #1
On 12/20/22 8:11 PM, Miaoqian Lin wrote:
> rdma_user_mmap_entry_get() take reference, we should release it when not
> need anymore, add the missing rdma_user_mmap_entry_put() in the error
> path to fix it.
> 
> Fixes: 155055771704 ("RDMA/erdma: Add verbs implementation")
> Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
> ---
>  drivers/infiniband/hw/erdma/erdma_verbs.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 

Good catch, thanks.

Acked-by: Cheng Xu <chengyou@linux.alibaba.com>


> diff --git a/drivers/infiniband/hw/erdma/erdma_verbs.c b/drivers/infiniband/hw/erdma/erdma_verbs.c
> index 5dab1e87975b..9c30d78730aa 100644
> --- a/drivers/infiniband/hw/erdma/erdma_verbs.c
> +++ b/drivers/infiniband/hw/erdma/erdma_verbs.c
> @@ -1110,12 +1110,14 @@ int erdma_mmap(struct ib_ucontext *ctx, struct vm_area_struct *vma)
>  		prot = pgprot_device(vma->vm_page_prot);
>  		break;
>  	default:
> -		return -EINVAL;
> +		err = -EINVAL;
> +		goto put_entry;
>  	}
>  
>  	err = rdma_user_mmap_io(ctx, vma, PFN_DOWN(entry->address), PAGE_SIZE,
>  				prot, rdma_entry);
>  
> +put_entry:
>  	rdma_user_mmap_entry_put(rdma_entry);
>  	return err;
>  }
Leon Romanovsky Dec. 28, 2022, 9:59 a.m. UTC | #2
On Tue, 20 Dec 2022 16:11:39 +0400, Miaoqian Lin wrote:
> rdma_user_mmap_entry_get() take reference, we should release it when not
> need anymore, add the missing rdma_user_mmap_entry_put() in the error
> path to fix it.
> 
> 

Applied, thanks!

[1/1] RDMA/erdma: Fix refcount leak in erdma_mmap
      https://git.kernel.org/rdma/rdma/c/ee84146c05ad23

Best regards,
diff mbox series

Patch

diff --git a/drivers/infiniband/hw/erdma/erdma_verbs.c b/drivers/infiniband/hw/erdma/erdma_verbs.c
index 5dab1e87975b..9c30d78730aa 100644
--- a/drivers/infiniband/hw/erdma/erdma_verbs.c
+++ b/drivers/infiniband/hw/erdma/erdma_verbs.c
@@ -1110,12 +1110,14 @@  int erdma_mmap(struct ib_ucontext *ctx, struct vm_area_struct *vma)
 		prot = pgprot_device(vma->vm_page_prot);
 		break;
 	default:
-		return -EINVAL;
+		err = -EINVAL;
+		goto put_entry;
 	}
 
 	err = rdma_user_mmap_io(ctx, vma, PFN_DOWN(entry->address), PAGE_SIZE,
 				prot, rdma_entry);
 
+put_entry:
 	rdma_user_mmap_entry_put(rdma_entry);
 	return err;
 }