* [PATCH v1] dmaengine: qcom: gpi: Fix channel cleanup in unwind path
@ 2026-08-03 12:03 Aniket Randive
2026-08-07 11:40 ` Mukesh Savaliya
0 siblings, 1 reply; 3+ messages in thread
From: Aniket Randive @ 2026-08-03 12:03 UTC (permalink / raw)
To: Vinod Koul
Cc: Frank Li, Dmitry Baryshkov, Kees Cook, Icenowy Zheng,
Jyothi Kumar Seerapu, Miaoqian Lin, linux-arm-msm, dmaengine,
linux-kernel, Aniket Randive
Fix three issues in the gpi_ch_init() error path.
Use the indexed channel in the error_start_chan and
error_alloc_chan unwind loops instead of the original gchan
pointer. Otherwise, each iteration operates on the same channel,
leaving sibling channels unreset and undeallocated on failure.
Clear pm_state after freeing the event ring in the error path.
gpi_alloc_ev_chan() sets pm_state to ACTIVE_STATE, but the error
path frees ev_ring without restoring pm_state. As a result,
gpi_free_chan_resources() may attempt to deallocate an already
freed event ring and issue a redundant EV_CMD_DEALLOC.
Also free ch_ring in gpi_alloc_chan_resources() if gpi_ch_init()
fails. The ring is allocated before calling gpi_ch_init(), so a
failure leaves it leaked without this free.
Fix all three issues by unwinding the correct channels, restoring
pm_state to DISABLE_STATE after freeing the event ring, and freeing
ch_ring on gpi_ch_init() failure.
Signed-off-by: Aniket Randive <aniket.randive@oss.qualcomm.com>
---
drivers/dma/qcom/gpi.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/drivers/dma/qcom/gpi.c b/drivers/dma/qcom/gpi.c
index a5055a6273af..c41bfac65ddf 100644
--- a/drivers/dma/qcom/gpi.c
+++ b/drivers/dma/qcom/gpi.c
@@ -1965,16 +1965,19 @@ static int gpi_ch_init(struct gchan *gchan)
error_start_chan:
for (i = i - 1; i >= 0; i--) {
gpi_stop_chan(&gpii->gchan[i]);
- gpi_send_cmd(gpii, gchan, GPI_CH_CMD_RESET);
+ gpi_send_cmd(gpii, &gpii->gchan[i], GPI_CH_CMD_RESET);
}
i = 2;
error_alloc_chan:
for (i = i - 1; i >= 0; i--)
- gpi_reset_chan(gchan, GPI_CH_CMD_DE_ALLOC);
+ gpi_reset_chan(&gpii->gchan[i], GPI_CH_CMD_DE_ALLOC);
error_alloc_ev_ring:
gpi_disable_interrupts(gpii);
error_config_int:
gpi_free_ring(&gpii->ev_ring, gpii);
+ write_lock_irq(&gpii->pm_lock);
+ gpii->pm_state = DISABLE_STATE;
+ write_unlock_irq(&gpii->pm_lock);
exit_gpi_init:
return ret;
}
@@ -2065,6 +2068,8 @@ static int gpi_alloc_chan_resources(struct dma_chan *chan)
goto xfer_alloc_err;
ret = gpi_ch_init(gchan);
+ if (ret)
+ gpi_free_ring(&gchan->ch_ring, gpii);
mutex_unlock(&gpii->ctrl_lock);
--
2.34.1
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v1] dmaengine: qcom: gpi: Fix channel cleanup in unwind path
2026-08-03 12:03 [PATCH v1] dmaengine: qcom: gpi: Fix channel cleanup in unwind path Aniket Randive
@ 2026-08-07 11:40 ` Mukesh Savaliya
2026-08-10 6:52 ` Aniket RANDIVE
0 siblings, 1 reply; 3+ messages in thread
From: Mukesh Savaliya @ 2026-08-07 11:40 UTC (permalink / raw)
To: Aniket Randive, Vinod Koul
Cc: Frank Li, Dmitry Baryshkov, Kees Cook, Icenowy Zheng,
Jyothi Kumar Seerapu, Miaoqian Lin, linux-arm-msm, dmaengine,
linux-kernel
On 8/3/2026 5:33 PM, Aniket Randive wrote:
> Fix three issues in the gpi_ch_init() error path.
>
start here mentioning the three problems first in generic way.
> Use the indexed channel in the error_start_chan and
> error_alloc_chan unwind loops instead of the original gchan
> pointer. Otherwise, each iteration operates on the same channel,
> leaving sibling channels unreset and undeallocated on failure.
meaning, channel cleanup not happened ? make it simpler anyway.
>
> Clear pm_state after freeing the event ring in the error path.
> gpi_alloc_ev_chan() sets pm_state to ACTIVE_STATE, but the error
> path frees ev_ring without restoring pm_state. As a result,
> gpi_free_chan_resources() may attempt to deallocate an already
> freed event ring and issue a redundant EV_CMD_DEALLOC.
>
Looking at your change, it looks we are cleaning up gpii iterating over
each channel along with setting proper state. Code seems simpler than
the commit log, so request you to simplify.
> Also free ch_ring in gpi_alloc_chan_resources() if gpi_ch_init()
> fails. The ring is allocated before calling gpi_ch_init(), so a
> failure leaves it leaked without this free.
>
> Fix all three issues by unwinding the correct channels, restoring
> pm_state to DISABLE_STATE after freeing the event ring, and freeing
> ch_ring on gpi_ch_init() failure.
>
> Signed-off-by: Aniket Randive <aniket.randive@oss.qualcomm.com>
> ---
> drivers/dma/qcom/gpi.c | 9 +++++++--
> 1 file changed, 7 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/dma/qcom/gpi.c b/drivers/dma/qcom/gpi.c
[...]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v1] dmaengine: qcom: gpi: Fix channel cleanup in unwind path
2026-08-07 11:40 ` Mukesh Savaliya
@ 2026-08-10 6:52 ` Aniket RANDIVE
0 siblings, 0 replies; 3+ messages in thread
From: Aniket RANDIVE @ 2026-08-10 6:52 UTC (permalink / raw)
To: Mukesh Savaliya, Vinod Koul
Cc: Frank Li, Dmitry Baryshkov, Kees Cook, Icenowy Zheng,
Jyothi Kumar Seerapu, Miaoqian Lin, linux-arm-msm, dmaengine,
linux-kernel
Thanks Mukesh for the review.
I will update the commit message as per your suggestion.
Thanks,
Aniket
On 8/7/2026 5:10 PM, Mukesh Savaliya wrote:
>
>
> On 8/3/2026 5:33 PM, Aniket Randive wrote:
>> Fix three issues in the gpi_ch_init() error path.
>>
> start here mentioning the three problems first in generic way.
>> Use the indexed channel in the error_start_chan and
>> error_alloc_chan unwind loops instead of the original gchan
>> pointer. Otherwise, each iteration operates on the same channel,
>> leaving sibling channels unreset and undeallocated on failure.
>
> meaning, channel cleanup not happened ? make it simpler anyway.
>>
>> Clear pm_state after freeing the event ring in the error path.
>> gpi_alloc_ev_chan() sets pm_state to ACTIVE_STATE, but the error
>> path frees ev_ring without restoring pm_state. As a result,
>> gpi_free_chan_resources() may attempt to deallocate an already
>> freed event ring and issue a redundant EV_CMD_DEALLOC.
>>
> Looking at your change, it looks we are cleaning up gpii iterating over
> each channel along with setting proper state. Code seems simpler than
> the commit log, so request you to simplify.
>
>> Also free ch_ring in gpi_alloc_chan_resources() if gpi_ch_init()
>> fails. The ring is allocated before calling gpi_ch_init(), so a
>> failure leaves it leaked without this free.
>>
>> Fix all three issues by unwinding the correct channels, restoring
>> pm_state to DISABLE_STATE after freeing the event ring, and freeing
>> ch_ring on gpi_ch_init() failure.
>>
>> Signed-off-by: Aniket Randive <aniket.randive@oss.qualcomm.com>
>> ---
>> drivers/dma/qcom/gpi.c | 9 +++++++--
>> 1 file changed, 7 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/dma/qcom/gpi.c b/drivers/dma/qcom/gpi.c
>
> [...]
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-08-10 6:53 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-08-03 12:03 [PATCH v1] dmaengine: qcom: gpi: Fix channel cleanup in unwind path Aniket Randive
2026-08-07 11:40 ` Mukesh Savaliya
2026-08-10 6:52 ` Aniket RANDIVE
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®