public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] IB/hfi1: fix a memleak in init_credit_return
@ 2024-01-12  8:55 Zhipeng Lu
  2024-01-14  9:04 ` Leon Romanovsky
  2024-01-25  9:56 ` Leon Romanovsky
  0 siblings, 2 replies; 5+ messages in thread
From: Zhipeng Lu @ 2024-01-12  8:55 UTC (permalink / raw)
  To: alexious
  Cc: Dennis Dalessandro, Jason Gunthorpe, Leon Romanovsky, Jubin John,
	Mitko Haralanov, Ravi Krishnaswamy, Harish Chegondi,
	Brendan Cunningham, linux-rdma, linux-kernel

When dma_alloc_coherent fails to allocate dd->cr_base[i].va,
init_credit_return should deallocate dd->cr_base and
dd->cr_base[i] that allocated before. Or those resources
would be never freed and a memleak is triggered.

Fixes: 7724105686e7 ("IB/hfi1: add driver files")
Signed-off-by: Zhipeng Lu <alexious@zju.edu.cn>
---
 drivers/infiniband/hw/hfi1/pio.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/infiniband/hw/hfi1/pio.c b/drivers/infiniband/hw/hfi1/pio.c
index 68c621ff59d0..5a91cbda4aee 100644
--- a/drivers/infiniband/hw/hfi1/pio.c
+++ b/drivers/infiniband/hw/hfi1/pio.c
@@ -2086,7 +2086,7 @@ int init_credit_return(struct hfi1_devdata *dd)
 				   "Unable to allocate credit return DMA range for NUMA %d\n",
 				   i);
 			ret = -ENOMEM;
-			goto done;
+			goto free_cr_base;
 		}
 	}
 	set_dev_node(&dd->pcidev->dev, dd->node);
@@ -2094,6 +2094,10 @@ int init_credit_return(struct hfi1_devdata *dd)
 	ret = 0;
 done:
 	return ret;
+
+free_cr_base:
+	free_credit_return(dd);
+	goto done;
 }
 
 void free_credit_return(struct hfi1_devdata *dd)
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-01-25  9:56 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-01-12  8:55 [PATCH] IB/hfi1: fix a memleak in init_credit_return Zhipeng Lu
2024-01-14  9:04 ` Leon Romanovsky
2024-01-18 23:14   ` Dennis Dalessandro
2024-01-21 13:09     ` Leon Romanovsky
2024-01-25  9:56 ` Leon Romanovsky

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox