[PATCH] spi: rockchip-sfc: skip DMA cleanup in PIO mode

From: Myeonghun Pak

Date: Fri Sep 11 2026 - 13:38:01 EST


With rockchip,sfc-no-dma, probe skips allocating and mapping the transfer
buffer. However, controller registration failure and driver removal still
call dma_unmap_single() for that nonexistent mapping.

Skip the DMA cleanup on registration failure when DMA is disabled, and
guard the buffer cleanup in remove with use_dma. Keep the existing
cleanup for allocation and mapping failures on the DMA path.

This issue was identified during our ongoing static-analysis research while
reviewing kernel code.

Fixes: ee795e82e101 ("spi: rockchip-sfc: Fix DMA-API usage")
Assisted-by: OpenAI:GPT-5.6
Co-developed-by: Ijae Kim <ae878000@xxxxxxxxx>
Signed-off-by: Ijae Kim <ae878000@xxxxxxxxx>
Signed-off-by: Myeonghun Pak <mhun512@xxxxxxxxx>
---
drivers/spi/spi-rockchip-sfc.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/drivers/spi/spi-rockchip-sfc.c b/drivers/spi/spi-rockchip-sfc.c
index 662a994da60beca33358dc6af09017e88771d017..21bd2e52d3989e3b371cf5c9ec8e4a22e22f17ed 100644
--- a/drivers/spi/spi-rockchip-sfc.c
+++ b/drivers/spi/spi-rockchip-sfc.c
@@ -719,6 +719,8 @@ static int rockchip_sfc_probe(struct platform_device *pdev)

return 0;
err_register:
+ if (!sfc->use_dma)
+ goto err_dma;
dma_unmap_single(dev, sfc->dma_buffer, sfc->max_iosize,
DMA_BIDIRECTIONAL);
err_dma_map:
@@ -743,9 +745,11 @@ static void rockchip_sfc_remove(struct platform_device *pdev)
struct spi_controller *host = sfc->host;

spi_unregister_controller(host);
- dma_unmap_single(&pdev->dev, sfc->dma_buffer, sfc->max_iosize,
- DMA_BIDIRECTIONAL);
- free_pages((unsigned long)sfc->buffer, get_order(sfc->max_iosize));
+ if (sfc->use_dma) {
+ dma_unmap_single(&pdev->dev, sfc->dma_buffer, sfc->max_iosize,
+ DMA_BIDIRECTIONAL);
+ free_pages((unsigned long)sfc->buffer, get_order(sfc->max_iosize));
+ }

clk_disable_unprepare(sfc->clk);
clk_disable_unprepare(sfc->hclk);
--
2.53.0