dmaengine: qcom_hidma: fix memory leak issues
Subsystems (4)
cover dmaengine: qcom_hidma: fix memory leak issues
fix a few memory leak issues.
Qasim Ijaz (2):
fix memory leak on probe failure
fix handoff FIFO memory leak on driver removal
drivers/dma/qcom/hidma_ll.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
Signature · 1 line
2.39.5
PATCH 1/2 dmaengine: qcom_hidma: fix memory leak on probe failure
hidma_ll_init() is invoked to create and initialise a struct hidma_lldev object during hidma probe. During this a FIFO buffer is allocated, but if some failure occurs after (like hidma_ll_setup failure) we should clean up the FIFO.
--- drivers/dma/qcom/hidma_ll.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/dma/qcom/hidma_ll.c +3 -1
@@ -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);
Signature · 1 line
2.39.5
Re: [PATCH 1/2] dmaengine: qcom_hidma: fix memory leak on probe failure
Quoted 8 lines · Qasim Ijaz
hidma_ll_init()is invoked to create and initialise a structhidma_lldevobject during hidma probe. During this a FIFO buffer is allocated, but if some failure occurs after (likehidma_ll_setupfailure) we should clean up the FIFO.Fixes d1615ca2e085 ("dmaengine: qcom_hidma: implement lower level hardware interface")Signed-off-by Qasim Ijaz <[email protected]>
PATCH 2/2 dmaengine: qcom_hidma: fix handoff FIFO memory leak on driver removal
In reply to Qasim Ijazhidma_ll_init() allocates a handoff FIFO, but the matching hidma_ll_uninit() function (which is invoked in remove()) never releases it, leaking memory.
To fix this call kfifo_free in hidma_ll_uninit().
--- drivers/dma/qcom/hidma_ll.c | 1 + 1 file changed, 1 insertion(+)
drivers/dma/qcom/hidma_ll.c +1 -0
@@ -816,6 +816,7 @@ int hidma_ll_uninit(struct hidma_lldev *lldev) required_bytes =sizeof (struct hidma_tre ) * lldev->nr_tres;tasklet_kill (&lldev->task); +kfifo_free (&lldev->handoff_fifo);memset (lldev->trepool,0 , required_bytes); lldev->trepool =NULL ;atomic_set (&lldev->pending_tre_count,0 );
Signature · 1 line
2.39.5
Re: [PATCH 2/2] dmaengine: qcom_hidma: fix handoff FIFO memory leak on driver removal
Quoted 19 lines · Qasim Ijaz
hidma_ll_init()allocates a handoff FIFO, but the matchinghidma_ll_uninit()function (which is invoked inremove()) never releases it, leaking memory.To fix this call
kfifo_freeinhidma_ll_uninit().Fixes d1615ca2e085 ("dmaengine: qcom_hidma: implement lower level hardware interface")Signed-off-by Qasim Ijaz <[email protected]>--- drivers/dma/qcom/hidma_ll.c | 1 + 1 file changed, 1 insertion(+)drivers/dma/qcom/hidma_ll.c +0
-0
drivers/dma/qcom/hidma_ll.c int hidma_ll_uninit(struct hidma_lldev *lldev) · line 822
Quoted 7 lines
drivers/dma/qcom/hidma_ll.c +1
-0@@ -816,6 +816,7 @@ int hidma_ll_uninit(struct hidma_lldev *lldev) required_bytes =sizeof (struct hidma_tre ) * lldev->nr_tres;tasklet_kill (&lldev->task); +kfifo_free (&lldev->handoff_fifo);memset (lldev->trepool,0 , required_bytes); lldev->trepool =NULL ;atomic_set (&lldev->pending_tre_count,0 );
Is it possible that the handoff_fifo is freed, then we could observe reset complete interrupts before they are being cleared in hidma_ll_uninit later on, which would lead to the following call chain
hidma_ll_inthandler - hidma_ll_int_handler_internal -hidma_handle_tre_completion - hidma_post_completed - tasklet_schedule(&lldev->task); - hidma_ll_tre_complete - kfifo_out
?
Sinan Kaya
maintainerRe: [PATCH 2/2] dmaengine: qcom_hidma: fix handoff FIFO memory leak on driver removal
Quoted 16 lines · Eugen Hristev
drivers/dma/qcom/hidma_ll.c int hidma_ll_uninit(struct hidma_lldev *lldev) · line 822
Quoted 12 lines
drivers/dma/qcom/hidma_ll.c +1
-0@@ -816,6 +816,7 @@ int hidma_ll_uninit(struct hidma_lldev *lldev) required_bytes =sizeof (struct hidma_tre ) * lldev->nr_tres;tasklet_kill (&lldev->task); +kfifo_free (&lldev->handoff_fifo);memset (lldev->trepool,0 , required_bytes); lldev->trepool =NULL ;atomic_set (&lldev->pending_tre_count,0 );Is it possible that the
handoff_fifois freed, then we could observe reset complete interrupts before they are being cleared inhidma_ll_uninitlater on, which would lead to the following call chain
Quoted 3 lines
hidma_ll_inthandler-hidma_ll_int_handler_internal-hidma_handle_tre_completion-hidma_post_completed-tasklet_schedule(&lldev->task); -hidma_ll_tre_complete-kfifo_out
According to the documentation, the way to guarantee this from not happening
is to call tasklet_disable() to ensure that tasklet completes execution. Only after that
data structures used by the tasklet can be freed.
I think proper order is:
1. tasklet_disable
2. tasklet_kill
3. kfifo_free
Re: [PATCH 2/2] dmaengine: qcom_hidma: fix handoff FIFO memory leak on driver removal
Quoted 28 lines · Sinan Kaya
Quoted 15 lines · Eugen Hristev
drivers/dma/qcom/hidma_ll.c int hidma_ll_uninit(struct hidma_lldev *lldev) · line 821
Quoted 11 lines
drivers/dma/qcom/hidma_ll.c +1
-0@@ -816,6 +816,7 @@ int hidma_ll_uninit(struct hidma_lldev *lldev) required_bytes =sizeof (struct hidma_tre ) * lldev->nr_tres;tasklet_kill (&lldev->task); +kfifo_free (&lldev->handoff_fifo);memset (lldev->trepool,0 , required_bytes); lldev->trepool =NULL ;atomic_set (&lldev->pending_tre_count,0 );Is it possible that the
handoff_fifois freed, then we could observe reset complete interrupts before they are being cleared inhidma_ll_uninitlater on, which would lead to the following call chainQuoted 3 lines
hidma_ll_inthandler-hidma_ll_int_handler_internal-hidma_handle_tre_completion-hidma_post_completed-tasklet_schedule(&lldev->task); -hidma_ll_tre_complete-kfifo_outAccording to the documentation, the way to guarantee this from not happening
is to call
tasklet_disable()to ensure that tasklet completes execution. Only after thatdata structures used by the tasklet can be freed.
Quoted 7 lines
I think proper order is:
1.
tasklet_disable2.
tasklet_kill3.
kfifo_free
Hi Sinan, hi Eugen,
Thanks for reviewing the patch and for pointing out the correct shutdown ordering.
If you’re both happy with it, I’ll send a v2 that calls tasklet_disable() before tasklet_kill(), then frees the handoff_fifo.
Just let me know and I’ll resend.
Thanks
Qasim
Quoted 3 lines
Sinan Kaya
maintainerRe: [PATCH 2/2] dmaengine: qcom_hidma: fix handoff FIFO memory leak on driver removal
Quoted 7 lines · Qasim Ijaz
Thanks for reviewing the patch and for pointing out the correct shutdown ordering.
If you’re both happy with it, I’ll send a v2 that calls
tasklet_disable()beforetasklet_kill(), then frees thehandoff_fifo.Just let me know and I’ll resend.
Sure, please test it on a test kernel module before posting with a tasklet.
This should be straightforward to verify.