* [PATCH] spi: stm32: fix double free of SRAM buffer on MDMA fallback
@ 2026-10-05 22:05 Pin-Hao Chen
2026-10-07 15:16 ` Mark Brown
0 siblings, 1 reply; 2+ messages in thread
From: Pin-Hao Chen @ 2026-10-05 22:05 UTC (permalink / raw)
To: Alain Volmat, Mark Brown
Cc: Maxime Coquelin, Alexandre Torgue, Clément Le Goffic,
linux-spi, linux-stm32, linux-arm-kernel, linux-kernel,
Pin-Hao Chen, stable
When the "rxm2m" MDMA channel cannot be obtained, the driver frees the
SRAM buffer and falls back to DMA-only mode. However, sram_rx_buf is
left pointing to the freed buffer.
As a result, stm32_spi_unprepare_msg() may clear the released SRAM
area, while stm32_spi_remove() or a later probe error path may free the
buffer again, triggering BUG_ON() in gen_pool_free_owner().
The probe error path also checks sram_pool instead of sram_rx_buf. If
the SRAM allocation failed and a later probe step fails,
gen_pool_free() may therefore be called with an unallocated buffer.
Clear sram_rx_buf after freeing it on the MDMA fallback path and use
the buffer pointer to determine whether cleanup is needed.
Fixes: d17dd2f1d8a1 ("spi: stm32: use STM32 DMA with STM32 MDMA to enhance DDR use")
Cc: stable@vger.kernel.org
Signed-off-by: Pin-Hao Chen <billy920225@gmail.com>
---
Found by code inspection. Compile-tested only (ARM multi_v7_defconfig,
W=1 and sparse); no hardware was available for runtime testing.
drivers/spi/spi-stm32.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/spi/spi-stm32.c b/drivers/spi/spi-stm32.c
index be88e62075af..605b847d8773 100644
--- a/drivers/spi/spi-stm32.c
+++ b/drivers/spi/spi-stm32.c
@@ -2511,6 +2511,7 @@ static int stm32_spi_probe(struct platform_device *pdev)
gen_pool_free(spi->sram_pool,
(unsigned long)spi->sram_rx_buf,
spi->sram_rx_buf_size);
+ spi->sram_rx_buf = NULL;
dev_warn(&pdev->dev,
"failed to request rx mdma channel, DMA only\n");
}
@@ -2548,7 +2549,7 @@ static int stm32_spi_probe(struct platform_device *pdev)
if (spi->mdma_rx)
dma_release_channel(spi->mdma_rx);
err_pool_free:
- if (spi->sram_pool)
+ if (spi->sram_rx_buf)
gen_pool_free(spi->sram_pool, (unsigned long)spi->sram_rx_buf,
spi->sram_rx_buf_size);
if (spi->dma_rx)
base-commit: fd99864b0ac936e870c7ae28354c5cd3dad5efd0
--
2.53.0
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] spi: stm32: fix double free of SRAM buffer on MDMA fallback
2026-10-05 22:05 [PATCH] spi: stm32: fix double free of SRAM buffer on MDMA fallback Pin-Hao Chen
@ 2026-10-07 15:16 ` Mark Brown
0 siblings, 0 replies; 2+ messages in thread
From: Mark Brown @ 2026-10-07 15:16 UTC (permalink / raw)
To: Alain Volmat, Pin-Hao Chen
Cc: Maxime Coquelin, Alexandre Torgue, Clément Le Goffic,
linux-spi, linux-stm32, linux-arm-kernel, linux-kernel, stable
On Tue, 06 Oct 2026 06:05:28 +0800, Pin-Hao Chen wrote:
> spi: stm32: fix double free of SRAM buffer on MDMA fallback
Applied to
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git for-7.4
Thanks!
[1/1] spi: stm32: fix double free of SRAM buffer on MDMA fallback
https://git.kernel.org/broonie/spi/c/0c5b0c3eb1d6
All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying
to this mail.
Thanks,
Mark
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-10-08 7:19 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-05 22:05 [PATCH] spi: stm32: fix double free of SRAM buffer on MDMA fallback Pin-Hao Chen
2026-10-07 15:16 ` Mark Brown
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox