mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 0/2] spi: atcspi200: two cleanup
@ 2026-04-16 16:27 Felix Gu
  2026-04-16 16:27 ` [PATCH 1/2] spi: atcspi200: fix use-after-free when driver unbind Felix Gu
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Felix Gu @ 2026-04-16 16:27 UTC (permalink / raw)
  To: CL Wang, Mark Brown; +Cc: linux-spi, linux-kernel, Felix Gu

Signed-off-by: Felix Gu <ustc.gu@gmail.com>
---
Felix Gu (2):
      spi: atcspi200: fix use-after-free when driver unbind
      spi: atcspi200: switch to devm functions

 drivers/spi/spi-atcspi200.c | 28 ++++++++++++----------------
 1 file changed, 12 insertions(+), 16 deletions(-)
---
base-commit: 936c21068d7ade00325e40d82bfd2f3f29d9f659
change-id: 20260416-atcspi-96784f8f2a56

Best regards,
-- 
Felix Gu <ustc.gu@gmail.com>


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

* [PATCH 1/2] spi: atcspi200: fix use-after-free when driver unbind
  2026-04-16 16:27 [PATCH 0/2] spi: atcspi200: two cleanup Felix Gu
@ 2026-04-16 16:27 ` Felix Gu
  2026-04-16 16:27 ` [PATCH 2/2] spi: atcspi200: switch to devm functions Felix Gu
  2026-04-26 23:33 ` [PATCH 0/2] spi: atcspi200: two cleanup Mark Brown
  2 siblings, 0 replies; 4+ messages in thread
From: Felix Gu @ 2026-04-16 16:27 UTC (permalink / raw)
  To: CL Wang, Mark Brown; +Cc: linux-spi, linux-kernel, Felix Gu

DMA resource is initialized after SPI controller registration. So
when driver unbind, this can trigger a use-after-free when DMA is
torn down while the controller is still alive and triggers DMA transfers.

Fixes: 34e3815ea459 ("spi: atcspi200: Add ATCSPI200 SPI controller driver")
Signed-off-by: Felix Gu <ustc.gu@gmail.com>
---
 drivers/spi/spi-atcspi200.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/drivers/spi/spi-atcspi200.c b/drivers/spi/spi-atcspi200.c
index 3832d9db3cbf..c5cf1aa2d674 100644
--- a/drivers/spi/spi-atcspi200.c
+++ b/drivers/spi/spi-atcspi200.c
@@ -575,12 +575,6 @@ static int atcspi_probe(struct platform_device *pdev)
 	if (ret)
 		goto free_controller;
 
-	ret = devm_spi_register_controller(&pdev->dev, host);
-	if (ret) {
-		dev_err_probe(spi->dev, ret,
-			      "Failed to register SPI controller\n");
-		goto free_controller;
-	}
 	spi->use_dma = false;
 	if (ATCSPI_DMA_SUPPORT) {
 		ret = atcspi_configure_dma(spi);
@@ -591,6 +585,13 @@ static int atcspi_probe(struct platform_device *pdev)
 			spi->use_dma = true;
 	}
 
+	ret = devm_spi_register_controller(&pdev->dev, host);
+	if (ret) {
+		dev_err_probe(spi->dev, ret,
+			      "Failed to register SPI controller\n");
+		goto free_controller;
+	}
+
 	return 0;
 
 free_controller:

-- 
2.43.0


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

* [PATCH 2/2] spi: atcspi200: switch to devm functions
  2026-04-16 16:27 [PATCH 0/2] spi: atcspi200: two cleanup Felix Gu
  2026-04-16 16:27 ` [PATCH 1/2] spi: atcspi200: fix use-after-free when driver unbind Felix Gu
@ 2026-04-16 16:27 ` Felix Gu
  2026-04-26 23:33 ` [PATCH 0/2] spi: atcspi200: two cleanup Mark Brown
  2 siblings, 0 replies; 4+ messages in thread
From: Felix Gu @ 2026-04-16 16:27 UTC (permalink / raw)
  To: CL Wang, Mark Brown; +Cc: linux-spi, linux-kernel, Felix Gu

Switch to use devm_spi_alloc_host and devm_mutex_init to make code clean.

Signed-off-by: Felix Gu <ustc.gu@gmail.com>
---
 drivers/spi/spi-atcspi200.c | 25 ++++++++++---------------
 1 file changed, 10 insertions(+), 15 deletions(-)

diff --git a/drivers/spi/spi-atcspi200.c b/drivers/spi/spi-atcspi200.c
index c5cf1aa2d674..6d4b6aeb3f5b 100644
--- a/drivers/spi/spi-atcspi200.c
+++ b/drivers/spi/spi-atcspi200.c
@@ -550,7 +550,7 @@ static int atcspi_probe(struct platform_device *pdev)
 	struct resource *mem_res;
 	int ret;
 
-	host = spi_alloc_host(&pdev->dev, sizeof(*spi));
+	host = devm_spi_alloc_host(&pdev->dev, sizeof(*spi));
 	if (!host)
 		return -ENOMEM;
 
@@ -559,21 +559,23 @@ static int atcspi_probe(struct platform_device *pdev)
 	spi->dev = &pdev->dev;
 	dev_set_drvdata(&pdev->dev, host);
 
-	mutex_init(&spi->mutex_lock);
+	ret = devm_mutex_init(&pdev->dev, &spi->mutex_lock);
+	if (ret)
+		return ret;
 
 	ret = atcspi_init_resources(pdev, spi, &mem_res);
 	if (ret)
-		goto free_controller;
+		return ret;
 
 	ret = atcspi_enable_clk(spi);
 	if (ret)
-		goto free_controller;
+		return ret;
 
 	atcspi_init_controller(pdev, spi, host, mem_res);
 
 	ret = atcspi_setup(spi);
 	if (ret)
-		goto free_controller;
+		return ret;
 
 	spi->use_dma = false;
 	if (ATCSPI_DMA_SUPPORT) {
@@ -586,18 +588,11 @@ static int atcspi_probe(struct platform_device *pdev)
 	}
 
 	ret = devm_spi_register_controller(&pdev->dev, host);
-	if (ret) {
-		dev_err_probe(spi->dev, ret,
-			      "Failed to register SPI controller\n");
-		goto free_controller;
-	}
+	if (ret)
+		return dev_err_probe(spi->dev, ret,
+				     "Failed to register SPI controller\n");
 
 	return 0;
-
-free_controller:
-	mutex_destroy(&spi->mutex_lock);
-	spi_controller_put(host);
-	return ret;
 }
 
 static int atcspi_suspend(struct device *dev)

-- 
2.43.0


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

* Re: [PATCH 0/2] spi: atcspi200: two cleanup
  2026-04-16 16:27 [PATCH 0/2] spi: atcspi200: two cleanup Felix Gu
  2026-04-16 16:27 ` [PATCH 1/2] spi: atcspi200: fix use-after-free when driver unbind Felix Gu
  2026-04-16 16:27 ` [PATCH 2/2] spi: atcspi200: switch to devm functions Felix Gu
@ 2026-04-26 23:33 ` Mark Brown
  2 siblings, 0 replies; 4+ messages in thread
From: Mark Brown @ 2026-04-26 23:33 UTC (permalink / raw)
  To: CL Wang, Felix Gu; +Cc: linux-spi, linux-kernel

On Fri, 17 Apr 2026 00:27:53 +0800, Felix Gu wrote:
> spi: atcspi200: two cleanup

Applied to

   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git for-7.2

Thanks!

[1/2] spi: atcspi200: fix use-after-free when driver unbind
      https://git.kernel.org/broonie/spi/c/565bdf45125a
[2/2] spi: atcspi200: switch to devm functions
      https://git.kernel.org/broonie/spi/c/aaea50c3bd76

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] 4+ messages in thread

end of thread, other threads:[~2026-04-27 10:20 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-04-16 16:27 [PATCH 0/2] spi: atcspi200: two cleanup Felix Gu
2026-04-16 16:27 ` [PATCH 1/2] spi: atcspi200: fix use-after-free when driver unbind Felix Gu
2026-04-16 16:27 ` [PATCH 2/2] spi: atcspi200: switch to devm functions Felix Gu
2026-04-26 23:33 ` [PATCH 0/2] spi: atcspi200: two cleanup 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®