From: Felix Gu <ustc.gu@gmail.com>
To: Ryan Wanner <ryan.wanner@microchip.com>,
Mark Brown <broonie@kernel.org>,
Nicolas Ferre <nicolas.ferre@microchip.com>,
Alexandre Belloni <alexandre.belloni@bootlin.com>,
Claudiu Beznea <claudiu.beznea@tuxon.dev>,
Radu Pirea <radu.pirea@microchip.com>,
Richard Genoud <richard.genoud@bootlin.com>,
Wenyou Yang <wenyou.yang@atmel.com>
Cc: linux-spi@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org,
Mark Brown <broonie@opensource.wolfsonmicro.com>,
Felix Gu <ustc.gu@gmail.com>
Subject: [PATCH 2/2] spi: atmel: fix DMA resource leak on probe error paths
Date: Sat, 16 May 2026 01:20:35 +0800 [thread overview]
Message-ID: <20260516-atmel-v1-2-674fb4707af6@gmail.com> (raw)
In-Reply-To: <20260516-atmel-v1-0-674fb4707af6@gmail.com>
The DMA resources allocated by atmel_spi_configure_dma() were not
released when devm_request_irq() or clk_prepare_enable() failed.
Route these two error paths through out_free_dma so that
atmel_spi_release_dma() releases the channels.
The same issue existed in the gclk_prepare_enable() failure path,
which jumped to out_disable_clk and returned without DMA cleanup.
The new fall-through from out_disable_clk into out_free_dma now
handles it as well.
Fixes: 1ccc404a7fc4 ("spi/spi-atmel: add dmaengine support")
Signed-off-by: Felix Gu <ustc.gu@gmail.com>
---
drivers/spi/spi-atmel.c | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)
diff --git a/drivers/spi/spi-atmel.c b/drivers/spi/spi-atmel.c
index e519a86a2b45..893f7c7ce358 100644
--- a/drivers/spi/spi-atmel.c
+++ b/drivers/spi/spi-atmel.c
@@ -1625,12 +1625,12 @@ static int atmel_spi_probe(struct platform_device *pdev)
0, dev_name(&pdev->dev), host);
}
if (ret)
- return ret;
+ goto out_free_dma;
/* Initialize the hardware */
ret = clk_prepare_enable(clk);
if (ret)
- return ret;
+ goto out_free_dma;
/*
* In cases where the peripheral clock is higher,the FLEX_SPI_CSRx.SCBR
@@ -1661,7 +1661,7 @@ static int atmel_spi_probe(struct platform_device *pdev)
ret = spi_register_controller(host);
if (ret)
- goto out_free_dma;
+ goto out_disable_rpm;
/* go! */
dev_info(&pdev->dev, "Atmel SPI Controller version 0x%x at 0x%08lx (irq %d)\n",
@@ -1670,18 +1670,18 @@ static int atmel_spi_probe(struct platform_device *pdev)
return 0;
-out_free_dma:
+out_disable_rpm:
pm_runtime_disable(&pdev->dev);
pm_runtime_set_suspended(&pdev->dev);
-
- if (as->use_dma)
- atmel_spi_release_dma(host, as);
-
spi_writel(as, CR, SPI_BIT(SWRST));
spi_writel(as, CR, SPI_BIT(SWRST)); /* AT91SAM9263 Rev B workaround */
- clk_disable_unprepare(as->gclk);
+ if (as->gclk)
+ clk_disable_unprepare(as->gclk);
out_disable_clk:
clk_disable_unprepare(clk);
+out_free_dma:
+ if (as->use_dma)
+ atmel_spi_release_dma(host, as);
return ret;
}
--
2.43.0
next prev parent reply other threads:[~2026-05-15 17:20 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-15 17:20 [PATCH 0/2] spi: atmel: two fixes Felix Gu
2026-05-15 17:20 ` [PATCH 1/2] spi: atmel: fix resource leak on DMA buffer allocation failure Felix Gu
2026-05-15 17:20 ` Felix Gu [this message]
2026-05-16 2:33 ` [PATCH 0/2] spi: atmel: two fixes 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=20260516-atmel-v1-2-674fb4707af6@gmail.com \
--to=ustc.gu@gmail.com \
--cc=alexandre.belloni@bootlin.com \
--cc=broonie@kernel.org \
--cc=broonie@opensource.wolfsonmicro.com \
--cc=claudiu.beznea@tuxon.dev \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-spi@vger.kernel.org \
--cc=nicolas.ferre@microchip.com \
--cc=radu.pirea@microchip.com \
--cc=richard.genoud@bootlin.com \
--cc=ryan.wanner@microchip.com \
--cc=wenyou.yang@atmel.com \
/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