diff mbox

[1/3] RDMA/ocrdma: Fix memory leak in _ocrdma_alloc_pd()

Message ID 1432966231-12125-1-git-send-email-roland@kernel.org (mailing list archive)
State Accepted
Headers show

Commit Message

Roland Dreier May 30, 2015, 6:10 a.m. UTC
From: Roland Dreier <roland@purestorage.com>

If ocrdma_get_pd_num() fails, then we need to free the pd struct we allocated.

This was detected by Coverity (CID 1271245).

Signed-off-by: Roland Dreier <roland@purestorage.com>
---
 drivers/infiniband/hw/ocrdma/ocrdma_verbs.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

Comments

Doug Ledford May 30, 2015, 3:26 p.m. UTC | #1
On Fri, 2015-05-29 at 23:10 -0700, Roland Dreier wrote:
> From: Roland Dreier <roland@purestorage.com>
> 
> If ocrdma_get_pd_num() fails, then we need to free the pd struct we allocated.
> 
> This was detected by Coverity (CID 1271245).
> 
> Signed-off-by: Roland Dreier <roland@purestorage.com>

Thanks, series applied.

> ---
>  drivers/infiniband/hw/ocrdma/ocrdma_verbs.c | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c b/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c
> index 9dcb66077d6c..fcb86749efc9 100644
> --- a/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c
> +++ b/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c
> @@ -375,7 +375,12 @@ static struct ocrdma_pd *_ocrdma_alloc_pd(struct ocrdma_dev *dev,
>  
>  	if (dev->pd_mgr->pd_prealloc_valid) {
>  		status = ocrdma_get_pd_num(dev, pd);
> -		return (status == 0) ? pd : ERR_PTR(status);
> +		if (status == 0) {
> +			return pd;
> +		} else {
> +			kfree(pd);
> +			return ERR_PTR(status);
> +		}
>  	}
>  
>  retry:
Devesh Sharma June 1, 2015, 5:24 a.m. UTC | #2
Acked-By: Devesh Sharma <devesh.sharma@avagotech.com>

On Sat, May 30, 2015 at 8:56 PM, Doug Ledford <dledford@redhat.com> wrote:
> On Fri, 2015-05-29 at 23:10 -0700, Roland Dreier wrote:
>> From: Roland Dreier <roland@purestorage.com>
>>
>> If ocrdma_get_pd_num() fails, then we need to free the pd struct we allocated.
>>
>> This was detected by Coverity (CID 1271245).
>>
>> Signed-off-by: Roland Dreier <roland@purestorage.com>
>
> Thanks, series applied.
>
>> ---
>>  drivers/infiniband/hw/ocrdma/ocrdma_verbs.c | 7 ++++++-
>>  1 file changed, 6 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c b/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c
>> index 9dcb66077d6c..fcb86749efc9 100644
>> --- a/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c
>> +++ b/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c
>> @@ -375,7 +375,12 @@ static struct ocrdma_pd *_ocrdma_alloc_pd(struct ocrdma_dev *dev,
>>
>>       if (dev->pd_mgr->pd_prealloc_valid) {
>>               status = ocrdma_get_pd_num(dev, pd);
>> -             return (status == 0) ? pd : ERR_PTR(status);
>> +             if (status == 0) {
>> +                     return pd;
>> +             } else {
>> +                     kfree(pd);
>> +                     return ERR_PTR(status);
>> +             }
>>       }
>>
>>  retry:
>
>
> --
> Doug Ledford <dledford@redhat.com>
>               GPG KeyID: 0E572FDD
>
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c b/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c
index 9dcb66077d6c..fcb86749efc9 100644
--- a/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c
+++ b/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c
@@ -375,7 +375,12 @@  static struct ocrdma_pd *_ocrdma_alloc_pd(struct ocrdma_dev *dev,
 
 	if (dev->pd_mgr->pd_prealloc_valid) {
 		status = ocrdma_get_pd_num(dev, pd);
-		return (status == 0) ? pd : ERR_PTR(status);
+		if (status == 0) {
+			return pd;
+		} else {
+			kfree(pd);
+			return ERR_PTR(status);
+		}
 	}
 
 retry: