From: Praveen Talari <praveen.talari@oss.qualcomm.com>
To: Aniket Randive <aniket.randive@oss.qualcomm.com>,
Vinod Koul <vkoul@kernel.org>, Frank Li <Frank.Li@kernel.org>,
Mukesh Kumar Savaliya <mukesh.savaliya@oss.qualcomm.com>
Cc: linux-arm-msm@vger.kernel.org, dmaengine@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3] dmaengine: qcom: gpi: Fix resource leaks as part of channel clean up
Date: Fri, 21 Aug 2026 10:37:33 +0530 [thread overview]
Message-ID: <39b33f3e-08bb-42eb-bc02-9de9810e0058@oss.qualcomm.com> (raw)
In-Reply-To: <20260819-gpi_bug_fix-v3-1-4c97333e6f5b@oss.qualcomm.com>
On 19-08-2026 17:09, Aniket Randive wrote:
> The gpi_ch_init() error handling paths do not fully clean up resources
> when channel initialization fails.
>
> The unwind paths iterate over the original channel pointer instead of
> the channels stored in gpii->gchan[], preventing previously initialized
> sibling channels from being properly reset and deallocated.
>
> In addition, gpi_alloc_chan_resources() allocates ch_ring before calling
> gpi_ch_init(), but does not release it when initialization fails,
> resulting in a memory leak.
>
> The event ring cleanup path also leaves the PM state unchanged after
> freeing the ring. As a result, subsequent cleanup may incorrectly assume
> that the ring is still allocated, leading to a redundant EV_CMD_DEALLOC
> command and an attempt to deallocate an already released ring.
>
> Fix the unwind paths to operate on the correct channels, release
> ch_ring when channel initialization fails, and restore the event ring
> PM state after freeing the ring.
>
> Signed-off-by: Aniket Randive <aniket.randive@oss.qualcomm.com>
> ---
> Changes in v3:
> - Updated the commit message as per Mukesh suggestion.
> - Link to v2: https://patch.msgid.link/20260810-gpi_bug_fix-v2-1-60555394cbf9@oss.qualcomm.com
>
> Changes in v2:
> - Updated the commit message as per Mukesh suggestion.
> ---
> 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);
Reviewed-by: Praveen Talari <praveen.talari@oss.qualcomm.com>
Thanks,
Praveen Talari
>
> mutex_unlock(&gpii->ctrl_lock);
>
>
> ---
> base-commit: 415606a7be939835db9b0d6b711887586646346d
> change-id: 20260803-gpi_bug_fix-b0b80ef315b5
>
> Best regards,
> --
> Aniket Randive <aniket.randive@oss.qualcomm.com>
>
>
prev parent reply other threads:[~2026-08-21 5:07 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-19 11:39 [PATCH v3] dmaengine: qcom: gpi: Fix resource leaks as part of channel clean up Aniket Randive
2026-08-19 11:56 ` sashiko-bot
2026-08-21 5:07 ` Praveen Talari [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=39b33f3e-08bb-42eb-bc02-9de9810e0058@oss.qualcomm.com \
--to=praveen.talari@oss.qualcomm.com \
--cc=Frank.Li@kernel.org \
--cc=aniket.randive@oss.qualcomm.com \
--cc=dmaengine@vger.kernel.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mukesh.savaliya@oss.qualcomm.com \
--cc=vkoul@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.