mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] spi: rockchip-sfc: skip DMA cleanup in PIO mode
@ 2026-09-11 17:27 Myeonghun Pak
  2026-09-11 18:47 ` Mark Brown
  0 siblings, 1 reply; 4+ messages in thread
From: Myeonghun Pak @ 2026-09-11 17:27 UTC (permalink / raw)
  To: Mark Brown, Heiko Stuebner
  Cc: linux-spi, linux-arm-kernel, linux-rockchip, linux-kernel,
	Marek Szyprowski, Ijae Kim

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@gmail.com>
Signed-off-by: Ijae Kim <ae878000@gmail.com>
Signed-off-by: Myeonghun Pak <mhun512@gmail.com>
---
 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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] spi: rockchip-sfc: skip DMA cleanup in PIO mode
  2026-09-11 17:27 [PATCH] spi: rockchip-sfc: skip DMA cleanup in PIO mode Myeonghun Pak
@ 2026-09-11 18:47 ` Mark Brown
  2026-09-12 19:00   ` [PATCH v2] " Myeonghun Pak
  0 siblings, 1 reply; 4+ messages in thread
From: Mark Brown @ 2026-09-11 18:47 UTC (permalink / raw)
  To: Myeonghun Pak
  Cc: Heiko Stuebner, linux-spi, linux-arm-kernel, linux-rockchip,
	linux-kernel, Marek Szyprowski, Ijae Kim

[-- Attachment #1: Type: text/plain, Size: 617 bytes --]

On Fri, Sep 11, 2026 at 01:27:01PM -0400, Myeonghun Pak wrote:
> 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.

>  err_register:
> +	if (!sfc->use_dma)
> +		goto err_dma;
>  	dma_unmap_single(dev, sfc->dma_buffer, sfc->max_iosize,
>  			 DMA_BIDIRECTIONAL);

Rather than adding use of goto to skip aroud within the cleanup here you
could guard the calls that need guarding with if statements, that would
look a lot less scary than jumping around like this.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v2] spi: rockchip-sfc: skip DMA cleanup in PIO mode
  2026-09-11 18:47 ` Mark Brown
@ 2026-09-12 19:00   ` Myeonghun Pak
  2026-09-13 11:34     ` Mark Brown
  0 siblings, 1 reply; 4+ messages in thread
From: Myeonghun Pak @ 2026-09-12 19:00 UTC (permalink / raw)
  To: Mark Brown, Heiko Stuebner
  Cc: linux-spi, linux-arm-kernel, linux-rockchip, linux-kernel,
	Marek Szyprowski, Ijae Kim

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.

Guard the DMA mapping and buffer cleanup 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@gmail.com>
Signed-off-by: Ijae Kim <ae878000@gmail.com>
Signed-off-by: Myeonghun Pak <mhun512@gmail.com>
---
Changes in v2:
- Guard the cleanup calls directly instead of jumping between error labels,
  as suggested by Mark Brown.

 drivers/spi/spi-rockchip-sfc.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/drivers/spi/spi-rockchip-sfc.c b/drivers/spi/spi-rockchip-sfc.c
index 662a994da60beca33358dc6af09017e88771d017..bc5537aee449e0c33c2d6ecf9d57205d432ec7b6 100644
--- a/drivers/spi/spi-rockchip-sfc.c
+++ b/drivers/spi/spi-rockchip-sfc.c
@@ -719,10 +719,12 @@ static int rockchip_sfc_probe(struct platform_device *pdev)
 
 	return 0;
 err_register:
-	dma_unmap_single(dev, sfc->dma_buffer, sfc->max_iosize,
-			 DMA_BIDIRECTIONAL);
+	if (sfc->use_dma)
+		dma_unmap_single(dev, sfc->dma_buffer, sfc->max_iosize,
+				 DMA_BIDIRECTIONAL);
 err_dma_map:
-	free_pages((unsigned long)sfc->buffer, get_order(sfc->max_iosize));
+	if (sfc->use_dma)
+		free_pages((unsigned long)sfc->buffer, get_order(sfc->max_iosize));
 err_dma:
 	pm_runtime_get_sync(dev);
 	pm_runtime_put_noidle(dev);
@@ -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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] spi: rockchip-sfc: skip DMA cleanup in PIO mode
  2026-09-12 19:00   ` [PATCH v2] " Myeonghun Pak
@ 2026-09-13 11:34     ` Mark Brown
  0 siblings, 0 replies; 4+ messages in thread
From: Mark Brown @ 2026-09-13 11:34 UTC (permalink / raw)
  To: Myeonghun Pak
  Cc: Heiko Stuebner, linux-spi, linux-arm-kernel, linux-rockchip,
	linux-kernel, Marek Szyprowski, Ijae Kim

[-- Attachment #1: Type: text/plain, Size: 559 bytes --]

On Sat, Sep 12, 2026 at 03:00:56PM -0400, Myeonghun Pak wrote:
> 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.

Please don't send new patches in reply to old patches or serieses, this
makes it harder for both people and tools to understand what is going
on - it can bury things in mailboxes and make it difficult to keep track
of what current patches are, both for the new patches and the old ones.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-09-13 11:34 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-11 17:27 [PATCH] spi: rockchip-sfc: skip DMA cleanup in PIO mode Myeonghun Pak
2026-09-11 18:47 ` Mark Brown
2026-09-12 19:00   ` [PATCH v2] " Myeonghun Pak
2026-09-13 11:34     ` Mark Brown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®