public inbox for stable@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/8] spi: cadence: fix controller deregistration
       [not found] <20260414134319.978196-1-johan@kernel.org>
@ 2026-04-14 13:43 ` Johan Hovold
  2026-04-14 13:43 ` [PATCH 2/8] spi: cadence-quadspi: " Johan Hovold
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 8+ messages in thread
From: Johan Hovold @ 2026-04-14 13:43 UTC (permalink / raw)
  To: Mark Brown; +Cc: linux-spi, linux-kernel, Johan Hovold, stable, Harini Katakam

Make sure to deregister the controller before disabling underlying
resources like clocks during driver unbind.

Fixes: c474b3866546 ("spi: Add driver for Cadence SPI controller")
Cc: stable@vger.kernel.org	# 3.16
Cc: Harini Katakam <harinik@xilinx.com>
Signed-off-by: Johan Hovold <johan@kernel.org>
---
 drivers/spi/spi-cadence.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/spi/spi-cadence.c b/drivers/spi/spi-cadence.c
index caa7a57e6d27..08d7dabe818d 100644
--- a/drivers/spi/spi-cadence.c
+++ b/drivers/spi/spi-cadence.c
@@ -777,6 +777,10 @@ static void cdns_spi_remove(struct platform_device *pdev)
 	struct spi_controller *ctlr = platform_get_drvdata(pdev);
 	struct cdns_spi *xspi = spi_controller_get_devdata(ctlr);
 
+	spi_controller_get(ctlr);
+
+	spi_unregister_controller(ctlr);
+
 	cdns_spi_write(xspi, CDNS_SPI_ER, CDNS_SPI_ER_DISABLE);
 
 	if (!spi_controller_is_target(ctlr)) {
@@ -784,7 +788,7 @@ static void cdns_spi_remove(struct platform_device *pdev)
 		pm_runtime_set_suspended(&pdev->dev);
 	}
 
-	spi_unregister_controller(ctlr);
+	spi_controller_put(ctlr);
 }
 
 /**
-- 
2.52.0


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

* [PATCH 2/8] spi: cadence-quadspi: fix controller deregistration
       [not found] <20260414134319.978196-1-johan@kernel.org>
  2026-04-14 13:43 ` [PATCH 1/8] spi: cadence: fix controller deregistration Johan Hovold
@ 2026-04-14 13:43 ` Johan Hovold
  2026-04-14 13:43 ` [PATCH 3/8] spi: mpc52xx: " Johan Hovold
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 8+ messages in thread
From: Johan Hovold @ 2026-04-14 13:43 UTC (permalink / raw)
  To: Mark Brown
  Cc: linux-spi, linux-kernel, Johan Hovold, stable,
	Khairul Anuar Romli

Make sure to deregister the controller before dropping the reference
count that allows new operations to start to allow SPI drivers to do I/O
during deregistration.

Fixes: 7446284023e8 ("spi: cadence-quadspi: Implement refcount to handle unbind during busy")
Cc: stable@vger.kernel.org	# 6.17
Cc: Khairul Anuar Romli <khairul.anuar.romli@altera.com>
Signed-off-by: Johan Hovold <johan@kernel.org>
---
 drivers/spi/spi-cadence-quadspi.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/spi/spi-cadence-quadspi.c b/drivers/spi/spi-cadence-quadspi.c
index 2ead419e896e..50ef65fc5ded 100644
--- a/drivers/spi/spi-cadence-quadspi.c
+++ b/drivers/spi/spi-cadence-quadspi.c
@@ -2020,13 +2020,13 @@ static void cqspi_remove(struct platform_device *pdev)
 
 	ddata = of_device_get_match_data(dev);
 
+	spi_unregister_controller(cqspi->host);
+
 	refcount_set(&cqspi->refcount, 0);
 
 	if (!refcount_dec_and_test(&cqspi->inflight_ops))
 		cqspi_wait_idle(cqspi);
 
-	spi_unregister_controller(cqspi->host);
-
 	if (cqspi->rx_chan)
 		dma_release_channel(cqspi->rx_chan);
 
-- 
2.52.0


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

* [PATCH 3/8] spi: mpc52xx: fix controller deregistration
       [not found] <20260414134319.978196-1-johan@kernel.org>
  2026-04-14 13:43 ` [PATCH 1/8] spi: cadence: fix controller deregistration Johan Hovold
  2026-04-14 13:43 ` [PATCH 2/8] spi: cadence-quadspi: " Johan Hovold
@ 2026-04-14 13:43 ` Johan Hovold
  2026-04-14 13:43 ` [PATCH 4/8] spi: mpc52xx: fix use-after-free on unbind Johan Hovold
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 8+ messages in thread
From: Johan Hovold @ 2026-04-14 13:43 UTC (permalink / raw)
  To: Mark Brown
  Cc: linux-spi, linux-kernel, Johan Hovold, stable, Grant Likely,
	Luotao Fu

Make sure to deregister the controller before disabling and releasing
underlying resources like interrupts and gpios during driver unbind.

Fixes: 42bbb70980f3 ("powerpc/5200: Add mpc5200-spi (non-PSC) device driver")
Fixes: b8d4e2ce60b6 ("mpc52xx_spi: add gpio chipselect")
Cc: stable@vger.kernel.org	# 2.6.33
Cc: Grant Likely <grant.likely@secretlab.ca>
Cc: Luotao Fu <l.fu@pengutronix.de>
Signed-off-by: Johan Hovold <johan@kernel.org>
---
 drivers/spi/spi-mpc52xx.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/spi/spi-mpc52xx.c b/drivers/spi/spi-mpc52xx.c
index 05bbd3795e7d..823b49f8ece2 100644
--- a/drivers/spi/spi-mpc52xx.c
+++ b/drivers/spi/spi-mpc52xx.c
@@ -517,6 +517,8 @@ static void mpc52xx_spi_remove(struct platform_device *op)
 	struct mpc52xx_spi *ms = spi_controller_get_devdata(host);
 	int i;
 
+	spi_unregister_controller(host);
+
 	cancel_work_sync(&ms->work);
 	free_irq(ms->irq0, ms);
 	free_irq(ms->irq1, ms);
@@ -525,7 +527,6 @@ static void mpc52xx_spi_remove(struct platform_device *op)
 		gpiod_put(ms->gpio_cs[i]);
 
 	kfree(ms->gpio_cs);
-	spi_unregister_controller(host);
 	iounmap(ms->regs);
 	spi_controller_put(host);
 }
-- 
2.52.0


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

* [PATCH 4/8] spi: mpc52xx: fix use-after-free on unbind
       [not found] <20260414134319.978196-1-johan@kernel.org>
                   ` (2 preceding siblings ...)
  2026-04-14 13:43 ` [PATCH 3/8] spi: mpc52xx: " Johan Hovold
@ 2026-04-14 13:43 ` Johan Hovold
  2026-04-14 13:43 ` [PATCH 5/8] spi: mxic: fix controller deregistration Johan Hovold
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 8+ messages in thread
From: Johan Hovold @ 2026-04-14 13:43 UTC (permalink / raw)
  To: Mark Brown; +Cc: linux-spi, linux-kernel, Johan Hovold, stable, Pei Xiao

The state machine work is scheduled by the interrupt handler and
therefore needs to be cancelled after disabling interrupts to avoid a
potential use-after-free.

Fixes: 984836621aad ("spi: mpc52xx: Add cancel_work_sync before module remove")
Cc: stable@vger.kernel.org
Cc: Pei Xiao <xiaopei01@kylinos.cn>
Signed-off-by: Johan Hovold <johan@kernel.org>
---
 drivers/spi/spi-mpc52xx.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/spi/spi-mpc52xx.c b/drivers/spi/spi-mpc52xx.c
index 823b49f8ece2..c8c8e6bdf421 100644
--- a/drivers/spi/spi-mpc52xx.c
+++ b/drivers/spi/spi-mpc52xx.c
@@ -519,10 +519,11 @@ static void mpc52xx_spi_remove(struct platform_device *op)
 
 	spi_unregister_controller(host);
 
-	cancel_work_sync(&ms->work);
 	free_irq(ms->irq0, ms);
 	free_irq(ms->irq1, ms);
 
+	cancel_work_sync(&ms->work);
+
 	for (i = 0; i < ms->gpio_cs_count; i++)
 		gpiod_put(ms->gpio_cs[i]);
 
-- 
2.52.0


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

* [PATCH 5/8] spi: mxic: fix controller deregistration
       [not found] <20260414134319.978196-1-johan@kernel.org>
                   ` (3 preceding siblings ...)
  2026-04-14 13:43 ` [PATCH 4/8] spi: mpc52xx: fix use-after-free on unbind Johan Hovold
@ 2026-04-14 13:43 ` Johan Hovold
  2026-04-14 13:43 ` [PATCH 6/8] spi: orion: " Johan Hovold
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 8+ messages in thread
From: Johan Hovold @ 2026-04-14 13:43 UTC (permalink / raw)
  To: Mark Brown; +Cc: linux-spi, linux-kernel, Johan Hovold, stable, Mason Yang

Make sure to deregister the controller before disabling underlying
resources like clocks (via runtime pm) during driver unbind.

Fixes: b942d80b0a39 ("spi: Add MXIC controller driver")
Cc: stable@vger.kernel.org	# 5.0: cc53711b2191
Cc: stable@vger.kernel.org	# 5.0
Cc: Mason Yang <masonccyang@mxic.com.tw>
Signed-off-by: Johan Hovold <johan@kernel.org>
---
 drivers/spi/spi-mxic.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/spi/spi-mxic.c b/drivers/spi/spi-mxic.c
index f9369c69911c..b0e7fc828a50 100644
--- a/drivers/spi/spi-mxic.c
+++ b/drivers/spi/spi-mxic.c
@@ -832,9 +832,10 @@ static void mxic_spi_remove(struct platform_device *pdev)
 	struct spi_controller *host = platform_get_drvdata(pdev);
 	struct mxic_spi *mxic = spi_controller_get_devdata(host);
 
+	spi_unregister_controller(host);
+
 	pm_runtime_disable(&pdev->dev);
 	mxic_spi_mem_ecc_remove(mxic);
-	spi_unregister_controller(host);
 }
 
 static const struct of_device_id mxic_spi_of_ids[] = {
-- 
2.52.0


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

* [PATCH 6/8] spi: orion: fix controller deregistration
       [not found] <20260414134319.978196-1-johan@kernel.org>
                   ` (4 preceding siblings ...)
  2026-04-14 13:43 ` [PATCH 5/8] spi: mxic: fix controller deregistration Johan Hovold
@ 2026-04-14 13:43 ` Johan Hovold
  2026-04-14 13:43 ` [PATCH 7/8] spi: topcliff-pch: " Johan Hovold
  2026-04-14 13:43 ` [PATCH 8/8] spi: topcliff-pch: fix use-after-free on unbind Johan Hovold
  7 siblings, 0 replies; 8+ messages in thread
From: Johan Hovold @ 2026-04-14 13:43 UTC (permalink / raw)
  To: Mark Brown; +Cc: linux-spi, linux-kernel, Johan Hovold, stable

Make sure to deregister the controller before disabling underlying
resources like clocks during driver unbind.

Fixes: 60cadec9da7b ("spi: new orion_spi driver")
Cc: stable@vger.kernel.org	# 2.6.27
Signed-off-by: Johan Hovold <johan@kernel.org>
---
 drivers/spi/spi-orion.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/spi/spi-orion.c b/drivers/spi/spi-orion.c
index 7a2186b51b4c..c54cd4ef09bd 100644
--- a/drivers/spi/spi-orion.c
+++ b/drivers/spi/spi-orion.c
@@ -801,10 +801,15 @@ static void orion_spi_remove(struct platform_device *pdev)
 	struct spi_controller *host = platform_get_drvdata(pdev);
 	struct orion_spi *spi = spi_controller_get_devdata(host);
 
+	spi_controller_get(host);
+
+	spi_unregister_controller(host);
+
 	pm_runtime_get_sync(&pdev->dev);
 	clk_disable_unprepare(spi->axi_clk);
 
-	spi_unregister_controller(host);
+	spi_controller_put(host);
+
 	pm_runtime_disable(&pdev->dev);
 }
 
-- 
2.52.0


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

* [PATCH 7/8] spi: topcliff-pch: fix controller deregistration
       [not found] <20260414134319.978196-1-johan@kernel.org>
                   ` (5 preceding siblings ...)
  2026-04-14 13:43 ` [PATCH 6/8] spi: orion: " Johan Hovold
@ 2026-04-14 13:43 ` Johan Hovold
  2026-04-14 13:43 ` [PATCH 8/8] spi: topcliff-pch: fix use-after-free on unbind Johan Hovold
  7 siblings, 0 replies; 8+ messages in thread
From: Johan Hovold @ 2026-04-14 13:43 UTC (permalink / raw)
  To: Mark Brown; +Cc: linux-spi, linux-kernel, Johan Hovold, stable, Masayuki Ohtake

Make sure to deregister the controller before disabling and releasing
underlying resources like interrupts and DMA during driver unbind.

Fixes: e8b17b5b3f30 ("spi/topcliff: Add topcliff platform controller hub (PCH) spi bus driver")
Cc: stable@vger.kernel.org	# 2.6.37
Cc: Masayuki Ohtake <masa-korg@dsn.okisemi.com>
Signed-off-by: Johan Hovold <johan@kernel.org>
---
 drivers/spi/spi-topcliff-pch.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/spi/spi-topcliff-pch.c b/drivers/spi/spi-topcliff-pch.c
index cae2dcefabea..c120436434d0 100644
--- a/drivers/spi/spi-topcliff-pch.c
+++ b/drivers/spi/spi-topcliff-pch.c
@@ -1406,6 +1406,10 @@ static void pch_spi_pd_remove(struct platform_device *plat_dev)
 	dev_dbg(&plat_dev->dev, "%s:[ch%d] irq=%d\n",
 		__func__, plat_dev->id, board_dat->pdev->irq);
 
+	spi_controller_get(data->host);
+
+	spi_unregister_controller(data->host);
+
 	if (use_dma)
 		pch_free_dma_buf(board_dat, data);
 
@@ -1433,7 +1437,8 @@ static void pch_spi_pd_remove(struct platform_device *plat_dev)
 	}
 
 	pci_iounmap(board_dat->pdev, data->io_remap_addr);
-	spi_unregister_controller(data->host);
+
+	spi_controller_put(data->host);
 }
 #ifdef CONFIG_PM
 static int pch_spi_pd_suspend(struct platform_device *pd_dev,
-- 
2.52.0


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

* [PATCH 8/8] spi: topcliff-pch: fix use-after-free on unbind
       [not found] <20260414134319.978196-1-johan@kernel.org>
                   ` (6 preceding siblings ...)
  2026-04-14 13:43 ` [PATCH 7/8] spi: topcliff-pch: " Johan Hovold
@ 2026-04-14 13:43 ` Johan Hovold
  7 siblings, 0 replies; 8+ messages in thread
From: Johan Hovold @ 2026-04-14 13:43 UTC (permalink / raw)
  To: Mark Brown; +Cc: linux-spi, linux-kernel, Johan Hovold, stable, Tomoya MORINAGA

Give the driver a chance to flush its queue before releasing the DMA
buffers on driver unbind

Fixes: c37f3c2749b5 ("spi/topcliff_pch: DMA support")
Cc: stable@vger.kernel.org	# 3.1
Cc: Tomoya MORINAGA <tomoya-linux@dsn.okisemi.com>
Signed-off-by: Johan Hovold <johan@kernel.org>
---
 drivers/spi/spi-topcliff-pch.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/spi/spi-topcliff-pch.c b/drivers/spi/spi-topcliff-pch.c
index c120436434d0..14d11450e86d 100644
--- a/drivers/spi/spi-topcliff-pch.c
+++ b/drivers/spi/spi-topcliff-pch.c
@@ -1410,9 +1410,6 @@ static void pch_spi_pd_remove(struct platform_device *plat_dev)
 
 	spi_unregister_controller(data->host);
 
-	if (use_dma)
-		pch_free_dma_buf(board_dat, data);
-
 	/* check for any pending messages; no action is taken if the queue
 	 * is still full; but at least we tried.  Unload anyway */
 	count = 500;
@@ -1436,6 +1433,9 @@ static void pch_spi_pd_remove(struct platform_device *plat_dev)
 		free_irq(board_dat->pdev->irq, data);
 	}
 
+	if (use_dma)
+		pch_free_dma_buf(board_dat, data);
+
 	pci_iounmap(board_dat->pdev, data->io_remap_addr);
 
 	spi_controller_put(data->host);
-- 
2.52.0


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

end of thread, other threads:[~2026-04-14 13:45 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20260414134319.978196-1-johan@kernel.org>
2026-04-14 13:43 ` [PATCH 1/8] spi: cadence: fix controller deregistration Johan Hovold
2026-04-14 13:43 ` [PATCH 2/8] spi: cadence-quadspi: " Johan Hovold
2026-04-14 13:43 ` [PATCH 3/8] spi: mpc52xx: " Johan Hovold
2026-04-14 13:43 ` [PATCH 4/8] spi: mpc52xx: fix use-after-free on unbind Johan Hovold
2026-04-14 13:43 ` [PATCH 5/8] spi: mxic: fix controller deregistration Johan Hovold
2026-04-14 13:43 ` [PATCH 6/8] spi: orion: " Johan Hovold
2026-04-14 13:43 ` [PATCH 7/8] spi: topcliff-pch: " Johan Hovold
2026-04-14 13:43 ` [PATCH 8/8] spi: topcliff-pch: fix use-after-free on unbind Johan Hovold

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