diff mbox series

qcom_hidma: fix memory leak of kfifo

Message ID 20241028170618.203023-1-keisuke.nishimura@inria.fr
State New
Headers show
Series qcom_hidma: fix memory leak of kfifo | expand

Commit Message

Keisuke Nishimura Oct. 28, 2024, 5:06 p.m. UTC
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 <keisuke.nishimura@inria.fr>
---
 drivers/dma/qcom/hidma_ll.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
diff mbox series

Patch

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);