[PATCH] qcom_hidma: fix memory leak of kfifo

DORMANTno replies

From: Keisuke Nishimura <hidden>
Date: 2024-10-28 17:09:36
Also in: linux-arm-msm
Subsystem: arm/qualcomm mailing list, dma generic offload engine subsystem, qualcomm hidma driver, the rest · Maintainers: Vinod Koul, Sinan Kaya, Linus Torvalds

The memory region allocated by kfifo_alloc() should be freed using
kfifo_free(). There are two possible cases that could result in a memory
leak:
- When hidma_ll_setup() fails, the initialization does not complete.
- hidma_ll_init() succeeds and the lldev is then uninitialized.

Fixes: d1615ca2e085 ("dmaengine: qcom_hidma: implement lower level hardware interface")
Signed-off-by: Keisuke Nishimura <redacted>
---
 drivers/dma/qcom/hidma_ll.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/drivers/dma/qcom/hidma_ll.c b/drivers/dma/qcom/hidma_ll.c
index 53244e0e34a3..6da611c61f8c 100644
--- a/drivers/dma/qcom/hidma_ll.c
+++ b/drivers/dma/qcom/hidma_ll.c
@@ -788,8 +788,10 @@ struct hidma_lldev *hidma_ll_init(struct device *dev, u32 nr_tres,
 		return NULL;
 
 	rc = hidma_ll_setup(lldev);
-	if (rc)
+	if (rc) {
+		kfifo_free(&lldev->handoff_fifo);
 		return NULL;
+	}
 
 	spin_lock_init(&lldev->lock);
 	tasklet_setup(&lldev->task, hidma_ll_tre_complete);
@@ -812,6 +814,7 @@ int hidma_ll_uninit(struct hidma_lldev *lldev)
 
 	lldev->initialized = 0;
 
+	kfifo_free(&lldev->handoff_fifo);
 	required_bytes = sizeof(struct hidma_tre) * lldev->nr_tres;
 	tasklet_kill(&lldev->task);
 	memset(lldev->trepool, 0, required_bytes);
-- 
2.34.1

Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help