* [PATCH 0/2] dmaengine: qcom_hidma: fix memory leak issues
@ 2025-06-01 22:42 Qasim Ijaz
2025-06-01 22:42 ` [PATCH 1/2] dmaengine: qcom_hidma: fix memory leak on probe failure Qasim Ijaz
2025-06-01 22:42 ` [PATCH 2/2] dmaengine: qcom_hidma: fix handoff FIFO memory leak on driver removal Qasim Ijaz
0 siblings, 2 replies; 8+ messages in thread
From: Qasim Ijaz @ 2025-06-01 22:42 UTC (permalink / raw)
To: Sinan Kaya, Vinod Koul, linux-arm-kernel, linux-arm-msm,
dmaengine, linux-kernel
Cc: Qasim Ijaz
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(-)
--
2.39.5
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 1/2] dmaengine: qcom_hidma: fix memory leak on probe failure
2025-06-01 22:42 [PATCH 0/2] dmaengine: qcom_hidma: fix memory leak issues Qasim Ijaz
@ 2025-06-01 22:42 ` Qasim Ijaz
2025-06-05 13:06 ` Eugen Hristev
2025-06-01 22:42 ` [PATCH 2/2] dmaengine: qcom_hidma: fix handoff FIFO memory leak on driver removal Qasim Ijaz
1 sibling, 1 reply; 8+ messages in thread
From: Qasim Ijaz @ 2025-06-01 22:42 UTC (permalink / raw)
To: Sinan Kaya, Vinod Koul, linux-arm-kernel, linux-arm-msm,
dmaengine, linux-kernel
Cc: Qasim Ijaz, stable
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.
Fixes: d1615ca2e085 ("dmaengine: qcom_hidma: implement lower level hardware interface")
Cc: stable@vger.kernel.org
Signed-off-by: Qasim Ijaz <qasdev00@gmail.com>
---
drivers/dma/qcom/hidma_ll.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/dma/qcom/hidma_ll.c b/drivers/dma/qcom/hidma_ll.c
index 53244e0e34a3..fee448499777 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);
--
2.39.5
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 2/2] dmaengine: qcom_hidma: fix handoff FIFO memory leak on driver removal
2025-06-01 22:42 [PATCH 0/2] dmaengine: qcom_hidma: fix memory leak issues Qasim Ijaz
2025-06-01 22:42 ` [PATCH 1/2] dmaengine: qcom_hidma: fix memory leak on probe failure Qasim Ijaz
@ 2025-06-01 22:42 ` Qasim Ijaz
2025-06-05 13:04 ` Eugen Hristev
1 sibling, 1 reply; 8+ messages in thread
From: Qasim Ijaz @ 2025-06-01 22:42 UTC (permalink / raw)
To: Sinan Kaya, Vinod Koul, linux-arm-kernel, linux-arm-msm,
dmaengine, linux-kernel
Cc: Qasim Ijaz, stable
hidma_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().
Fixes: d1615ca2e085 ("dmaengine: qcom_hidma: implement lower level hardware interface")
Cc: stable@vger.kernel.org
Signed-off-by: Qasim Ijaz <qasdev00@gmail.com>
---
drivers/dma/qcom/hidma_ll.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/dma/qcom/hidma_ll.c b/drivers/dma/qcom/hidma_ll.c
index fee448499777..0c2bae46746c 100644
--- a/drivers/dma/qcom/hidma_ll.c
+++ b/drivers/dma/qcom/hidma_ll.c
@@ -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);
--
2.39.5
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH 2/2] dmaengine: qcom_hidma: fix handoff FIFO memory leak on driver removal
2025-06-01 22:42 ` [PATCH 2/2] dmaengine: qcom_hidma: fix handoff FIFO memory leak on driver removal Qasim Ijaz
@ 2025-06-05 13:04 ` Eugen Hristev
2025-06-06 13:35 ` Sinan Kaya
0 siblings, 1 reply; 8+ messages in thread
From: Eugen Hristev @ 2025-06-05 13:04 UTC (permalink / raw)
To: Qasim Ijaz, Sinan Kaya, Vinod Koul, linux-arm-kernel,
linux-arm-msm, dmaengine, linux-kernel
Cc: stable
On 6/2/25 01:42, Qasim Ijaz wrote:
> hidma_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().
>
> Fixes: d1615ca2e085 ("dmaengine: qcom_hidma: implement lower level hardware interface")
> Cc: stable@vger.kernel.org
> Signed-off-by: Qasim Ijaz <qasdev00@gmail.com>
>
> ---
> drivers/dma/qcom/hidma_ll.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/drivers/dma/qcom/hidma_ll.c b/drivers/dma/qcom/hidma_ll.c
> index fee448499777..0c2bae46746c 100644
> --- a/drivers/dma/qcom/hidma_ll.c
> +++ b/drivers/dma/qcom/hidma_ll.c
> @@ -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
?
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 1/2] dmaengine: qcom_hidma: fix memory leak on probe failure
2025-06-01 22:42 ` [PATCH 1/2] dmaengine: qcom_hidma: fix memory leak on probe failure Qasim Ijaz
@ 2025-06-05 13:06 ` Eugen Hristev
0 siblings, 0 replies; 8+ messages in thread
From: Eugen Hristev @ 2025-06-05 13:06 UTC (permalink / raw)
To: Qasim Ijaz, Sinan Kaya, Vinod Koul, linux-arm-kernel,
linux-arm-msm, dmaengine, linux-kernel
Cc: stable
On 6/2/25 01:42, Qasim Ijaz wrote:
> 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.
>
> Fixes: d1615ca2e085 ("dmaengine: qcom_hidma: implement lower level hardware interface")
> Cc: stable@vger.kernel.org
> Signed-off-by: Qasim Ijaz <qasdev00@gmail.com>
Reviewed-by: Eugen Hristev <eugen.hristev@linaro.org>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 2/2] dmaengine: qcom_hidma: fix handoff FIFO memory leak on driver removal
2025-06-05 13:04 ` Eugen Hristev
@ 2025-06-06 13:35 ` Sinan Kaya
2025-06-15 19:15 ` Qasim Ijaz
0 siblings, 1 reply; 8+ messages in thread
From: Sinan Kaya @ 2025-06-06 13:35 UTC (permalink / raw)
To: Eugen Hristev, Qasim Ijaz, Vinod Koul, linux-arm-kernel,
linux-arm-msm, dmaengine, linux-kernel
Cc: stable
On 6/5/2025 9:04 AM, Eugen Hristev wrote:
>> diff --git a/drivers/dma/qcom/hidma_ll.c b/drivers/dma/qcom/hidma_ll.c
>> index fee448499777..0c2bae46746c 100644
>> --- a/drivers/dma/qcom/hidma_ll.c
>> +++ b/drivers/dma/qcom/hidma_ll.c
>> @@ -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
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
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 2/2] dmaengine: qcom_hidma: fix handoff FIFO memory leak on driver removal
2025-06-06 13:35 ` Sinan Kaya
@ 2025-06-15 19:15 ` Qasim Ijaz
2025-06-16 21:59 ` Sinan Kaya
0 siblings, 1 reply; 8+ messages in thread
From: Qasim Ijaz @ 2025-06-15 19:15 UTC (permalink / raw)
To: Sinan Kaya
Cc: Eugen Hristev, Vinod Koul, linux-arm-kernel, linux-arm-msm,
dmaengine, linux-kernel, stable
On Fri, Jun 06, 2025 at 09:35:44AM -0400, Sinan Kaya wrote:
>
> On 6/5/2025 9:04 AM, Eugen Hristev wrote:
> > > diff --git a/drivers/dma/qcom/hidma_ll.c b/drivers/dma/qcom/hidma_ll.c
> > > index fee448499777..0c2bae46746c 100644
> > > --- a/drivers/dma/qcom/hidma_ll.c
> > > +++ b/drivers/dma/qcom/hidma_ll.c
> > > @@ -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
>
> 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
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
>
>
>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 2/2] dmaengine: qcom_hidma: fix handoff FIFO memory leak on driver removal
2025-06-15 19:15 ` Qasim Ijaz
@ 2025-06-16 21:59 ` Sinan Kaya
0 siblings, 0 replies; 8+ messages in thread
From: Sinan Kaya @ 2025-06-16 21:59 UTC (permalink / raw)
To: Qasim Ijaz
Cc: Eugen Hristev, Vinod Koul, linux-arm-kernel, linux-arm-msm,
dmaengine, linux-kernel, stable
On 6/15/2025 3:15 PM, Qasim Ijaz wrote:
> 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.
Sure, please test it on a test kernel module before posting with a tasklet.
This should be straightforward to verify.
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2025-06-16 22:02 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-01 22:42 [PATCH 0/2] dmaengine: qcom_hidma: fix memory leak issues Qasim Ijaz
2025-06-01 22:42 ` [PATCH 1/2] dmaengine: qcom_hidma: fix memory leak on probe failure Qasim Ijaz
2025-06-05 13:06 ` Eugen Hristev
2025-06-01 22:42 ` [PATCH 2/2] dmaengine: qcom_hidma: fix handoff FIFO memory leak on driver removal Qasim Ijaz
2025-06-05 13:04 ` Eugen Hristev
2025-06-06 13:35 ` Sinan Kaya
2025-06-15 19:15 ` Qasim Ijaz
2025-06-16 21:59 ` Sinan Kaya
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).