RDMA/ocrdma: Fix memory leak in _ocrdma_alloc_pd()
authorRoland Dreier <roland@purestorage.com>
Sat, 30 May 2015 06:10:31 +0000 (23:10 -0700)
committerDoug Ledford <dledford@redhat.com>
Tue, 2 Jun 2015 13:22:31 +0000 (09:22 -0400)
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>
Acked-By: Devesh Sharma <devesh.sharma@avagotech.com>
Signed-off-by: Doug Ledford <dledford@redhat.com>
drivers/infiniband/hw/ocrdma/ocrdma_verbs.c

index 877175563634df79a889ed8a428405258b9df1e4..cf1f515efda8e5e2190d93a42a9c5f14833da560 100644 (file)
@@ -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: