From: Felix Gu <ustc.gu@gmail.com>
To: CL Wang <cl634@andestech.com>, Mark Brown <broonie@kernel.org>
Cc: linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org,
Felix Gu <ustc.gu@gmail.com>
Subject: [PATCH] spi: atcspi200: Fix double-free in atcspi_configure_dma()
Date: Thu, 05 Mar 2026 20:22:38 +0800 [thread overview]
Message-ID: <20260305-atcspi2000-v1-1-eafe08dcca60@gmail.com> (raw)
The driver uses devm_dma_request_chan() which registers automatic cleanup
via devm_add_action_or_reset(). Calling dma_release_channel() manually on
the RX channel when TX channel request fails causes a double-free when
the devm cleanup runs.
Remove the unnecessary manual cleanup and simplify the error handling
since devm will properly release channels on probe failure or driver
detach.
Fixes: 34e3815ea459 ("spi: atcspi200: Add ATCSPI200 SPI controller driver")
Signed-off-by: Felix Gu <ustc.gu@gmail.com>
---
drivers/spi/spi-atcspi200.c | 28 +++++++---------------------
1 file changed, 7 insertions(+), 21 deletions(-)
diff --git a/drivers/spi/spi-atcspi200.c b/drivers/spi/spi-atcspi200.c
index 2075058387f3..dd19fe9f9ee7 100644
--- a/drivers/spi/spi-atcspi200.c
+++ b/drivers/spi/spi-atcspi200.c
@@ -497,31 +497,17 @@ static int atcspi_init_resources(struct platform_device *pdev,
static int atcspi_configure_dma(struct atcspi_dev *spi)
{
- struct dma_chan *dma_chan;
- int ret = 0;
+ spi->host->dma_rx = devm_dma_request_chan(spi->dev, "rx");
+ if (IS_ERR(spi->host->dma_rx))
+ return PTR_ERR(spi->host->dma_rx);
- dma_chan = devm_dma_request_chan(spi->dev, "rx");
- if (IS_ERR(dma_chan)) {
- ret = PTR_ERR(dma_chan);
- goto err_exit;
- }
- spi->host->dma_rx = dma_chan;
+ spi->host->dma_tx = devm_dma_request_chan(spi->dev, "tx");
+ if (IS_ERR(spi->host->dma_tx))
+ return PTR_ERR(spi->host->dma_tx);
- dma_chan = devm_dma_request_chan(spi->dev, "tx");
- if (IS_ERR(dma_chan)) {
- ret = PTR_ERR(dma_chan);
- goto free_rx;
- }
- spi->host->dma_tx = dma_chan;
init_completion(&spi->dma_completion);
- return ret;
-
-free_rx:
- dma_release_channel(spi->host->dma_rx);
- spi->host->dma_rx = NULL;
-err_exit:
- return ret;
+ return 0;
}
static int atcspi_enable_clk(struct atcspi_dev *spi)
---
base-commit: fc7b1a72c6cd5cbbd989c6c32a6486e3e4e3594d
change-id: 20260305-atcspi2000-de58894938cd
Best regards,
--
Felix Gu <ustc.gu@gmail.com>
next reply other threads:[~2026-03-05 12:22 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-05 12:22 Felix Gu [this message]
2026-03-09 19:06 ` [PATCH] spi: atcspi200: Fix double-free in atcspi_configure_dma() Mark Brown
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=20260305-atcspi2000-v1-1-eafe08dcca60@gmail.com \
--to=ustc.gu@gmail.com \
--cc=broonie@kernel.org \
--cc=cl634@andestech.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-spi@vger.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox