Linux SPI subsystem development
 help / color / mirror / Atom feed
* [PATCH 0/2] spi: cadence-quadspi: fix probe error path and remove
@ 2026-07-31 10:53 Diogo Ivo (Schneider Electric)
  2026-07-31 10:53 ` [PATCH 1/2] spi: cadence-quadspi: fix runtime pm cleanup on probe failure/unbind Diogo Ivo (Schneider Electric)
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Diogo Ivo (Schneider Electric) @ 2026-07-31 10:53 UTC (permalink / raw)
  To: Mark Brown, Matthew Gerlach, Khairul Anuar Romli,
	Greg Kroah-Hartman, Dan Carpenter
  Cc: miquel.raynal, thomas.petazzoni, Pascal EBERHARD, linux-spi,
	linux-kernel, Diogo Ivo (Schneider Electric), stable

This series fixes two resource leaks in the cadence-quadspi driver's
probe error path and remove callback.

Patch 1 fixes an imbalanced pm_runtime_enable()/pm_runtime_disable()
pair: when probe defers after cqspi_request_mmap_dma(),
pm_runtime_disable() is called without a prior pm_runtime_enable().
It also adds the missing pm_runtime_dont_use_autosuspend() in both
the probe error path and the remove callback and a missing
pm_runtime_put_noidle() in the probe error path. This consolidates
fixes from upstream commits 5ff4d5d1af0c and 5e8bb0cc72f1.

Patch 2 fixes a DMA channel leak: when spi_register_controller() fails,
the channel acquired via cqspi_request_mmap_dma() is never released.
A dedicated error label is added to release it before the runtime PM
teardown. This fix is one part of upstream commit f18c8cfa4f1a.

Signed-off-by: Diogo Ivo (Schneider Electric) <diogo.ivo@bootlin.com>
---
Diogo Ivo (Schneider Electric) (2):
      spi: cadence-quadspi: fix runtime pm cleanup on probe failure/unbind
      spi: cadence-quadspi: release DMA channel on probe failure

 drivers/spi/spi-cadence-quadspi.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
---
base-commit: 52a355b23cd2dd77b683ed1a1bbe2b7408bd9c74
change-id: 20260730-cqspi-pm_runtime-a8a1c6122944

Best regards,
--  
Diogo Ivo <diogo.ivo@bootlin.com>


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

* [PATCH 1/2] spi: cadence-quadspi: fix runtime pm cleanup on probe failure/unbind
  2026-07-31 10:53 [PATCH 0/2] spi: cadence-quadspi: fix probe error path and remove Diogo Ivo (Schneider Electric)
@ 2026-07-31 10:53 ` Diogo Ivo (Schneider Electric)
  2026-07-31 10:53 ` [PATCH 2/2] spi: cadence-quadspi: release DMA channel on probe failure Diogo Ivo (Schneider Electric)
  2026-07-31 23:48 ` [PATCH 0/2] spi: cadence-quadspi: fix probe error path and remove Mark Brown
  2 siblings, 0 replies; 6+ messages in thread
From: Diogo Ivo (Schneider Electric) @ 2026-07-31 10:53 UTC (permalink / raw)
  To: Mark Brown, Matthew Gerlach, Khairul Anuar Romli,
	Greg Kroah-Hartman, Dan Carpenter
  Cc: miquel.raynal, thomas.petazzoni, Pascal EBERHARD, linux-spi,
	linux-kernel, Diogo Ivo (Schneider Electric), stable

Currently the probe cleanup path is imbalanced regarding
pm_runtime_enable() and pm_runtime_disable(). For example, if the probe
defers after calling cqspi_request_mmap_dma() pm_runtime_disable() will
be called without a prior call to pm_runtime_enable(), causing an
imbalance. Furthermore, the cleanup path does not undo all the runtime
calls made while probing.

Fix this by enforcing the correct correspondence between
pm_runtime_enable() and pm_runtime_resume() and add the missing PM
cleanup calls.

As the history of this driver in mainline is convoluted with several
rounds of fixes it includes the fixes from two commits, namely
commit 5ff4d5d1af0c ("spi: cadence-quadspi: fix runtime pm disable
imbalance on probe failure") and commit 5e8bb0cc72f1 ("spi:
cadence-quadspi: fix runtime pm and clock imbalance on unbind").

Fixes: 74b0b4cf13fc ("spi: spi-cadence-quadspi: Fix pm runtime unbalance")
Cc: stable@vger.kernel.org
Signed-off-by: Diogo Ivo (Schneider Electric) <diogo.ivo@bootlin.com>
---
 drivers/spi/spi-cadence-quadspi.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/drivers/spi/spi-cadence-quadspi.c b/drivers/spi/spi-cadence-quadspi.c
index da8401261bbc..d749dee54015 100644
--- a/drivers/spi/spi-cadence-quadspi.c
+++ b/drivers/spi/spi-cadence-quadspi.c
@@ -1862,7 +1862,6 @@ static int cqspi_probe(struct platform_device *pdev)
 	if (ret)
 		return ret;
 
-
 	ret = clk_prepare_enable(cqspi->clk);
 	if (ret) {
 		dev_err(dev, "Cannot enable QSPI clock.\n");
@@ -1983,16 +1982,19 @@ static int cqspi_probe(struct platform_device *pdev)
 	ret = spi_register_controller(host);
 	if (ret) {
 		dev_err(&pdev->dev, "failed to register SPI ctlr %d\n", ret);
-		goto probe_setup_failed;
+		goto disable_rpm;
 	}
 
 	pm_runtime_mark_last_busy(dev);
 	pm_runtime_put_autosuspend(dev);
 
 	return 0;
+disable_rpm:
+	pm_runtime_put_noidle(dev);
+	pm_runtime_dont_use_autosuspend(dev);
+	pm_runtime_disable(dev);
 probe_setup_failed:
 	cqspi_controller_enable(cqspi, 0);
-	pm_runtime_disable(dev);
 probe_reset_failed:
 	if (cqspi->is_jh7110)
 		cqspi_jh7110_disable_clk(pdev, cqspi);
@@ -2026,6 +2028,7 @@ static void cqspi_remove(struct platform_device *pdev)
 		cqspi_jh7110_disable_clk(pdev, cqspi);
 
 	pm_runtime_put_sync(&pdev->dev);
+	pm_runtime_dont_use_autosuspend(&pdev->dev);
 	pm_runtime_disable(&pdev->dev);
 }
 

-- 
2.55.0


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

* [PATCH 2/2] spi: cadence-quadspi: release DMA channel on probe failure
  2026-07-31 10:53 [PATCH 0/2] spi: cadence-quadspi: fix probe error path and remove Diogo Ivo (Schneider Electric)
  2026-07-31 10:53 ` [PATCH 1/2] spi: cadence-quadspi: fix runtime pm cleanup on probe failure/unbind Diogo Ivo (Schneider Electric)
@ 2026-07-31 10:53 ` Diogo Ivo (Schneider Electric)
  2026-07-31 23:48 ` [PATCH 0/2] spi: cadence-quadspi: fix probe error path and remove Mark Brown
  2 siblings, 0 replies; 6+ messages in thread
From: Diogo Ivo (Schneider Electric) @ 2026-07-31 10:53 UTC (permalink / raw)
  To: Mark Brown, Matthew Gerlach, Khairul Anuar Romli,
	Greg Kroah-Hartman, Dan Carpenter
  Cc: miquel.raynal, thomas.petazzoni, Pascal EBERHARD, linux-spi,
	linux-kernel, Diogo Ivo (Schneider Electric), stable

When spi_register_controller() fails in cqspi_probe(), the DMA channel
acquired via cqspi_request_mmap_dma() is not released, leaking the channel.
Add a dedicated error label to release the DMA channel before the
existing runtime PM teardown path.

This fix is one part of upstream commit f18c8cfa4f1a ("spi: cadence-qspi:
Fix probe error path and remove").

Fixes: b85815675fc5 ("spi: cadence-quadspi: fix cleanup of rx_chan on failure paths")
Cc: stable@vger.kernel.org
Signed-off-by: Diogo Ivo (Schneider Electric) <diogo.ivo@bootlin.com>
---
 drivers/spi/spi-cadence-quadspi.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/spi/spi-cadence-quadspi.c b/drivers/spi/spi-cadence-quadspi.c
index d749dee54015..66304664a1cf 100644
--- a/drivers/spi/spi-cadence-quadspi.c
+++ b/drivers/spi/spi-cadence-quadspi.c
@@ -1982,14 +1982,17 @@ static int cqspi_probe(struct platform_device *pdev)
 	ret = spi_register_controller(host);
 	if (ret) {
 		dev_err(&pdev->dev, "failed to register SPI ctlr %d\n", ret);
-		goto disable_rpm;
+		goto release_dma_chan;
 	}
 
 	pm_runtime_mark_last_busy(dev);
 	pm_runtime_put_autosuspend(dev);
 
 	return 0;
-disable_rpm:
+release_dma_chan:
+	if (cqspi->rx_chan)
+		dma_release_channel(cqspi->rx_chan);
+
 	pm_runtime_put_noidle(dev);
 	pm_runtime_dont_use_autosuspend(dev);
 	pm_runtime_disable(dev);

-- 
2.55.0


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

* Re: [PATCH 0/2] spi: cadence-quadspi: fix probe error path and remove
  2026-07-31 10:53 [PATCH 0/2] spi: cadence-quadspi: fix probe error path and remove Diogo Ivo (Schneider Electric)
  2026-07-31 10:53 ` [PATCH 1/2] spi: cadence-quadspi: fix runtime pm cleanup on probe failure/unbind Diogo Ivo (Schneider Electric)
  2026-07-31 10:53 ` [PATCH 2/2] spi: cadence-quadspi: release DMA channel on probe failure Diogo Ivo (Schneider Electric)
@ 2026-07-31 23:48 ` Mark Brown
  2026-08-01 11:27   ` Diogo Ivo
  2 siblings, 1 reply; 6+ messages in thread
From: Mark Brown @ 2026-07-31 23:48 UTC (permalink / raw)
  To: Diogo Ivo (Schneider Electric)
  Cc: Matthew Gerlach, Khairul Anuar Romli, Greg Kroah-Hartman,
	Dan Carpenter, miquel.raynal, thomas.petazzoni, Pascal EBERHARD,
	linux-spi, linux-kernel, stable

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

On Fri, Jul 31, 2026 at 12:53:45PM +0200, Diogo Ivo (Schneider Electric) wrote:
> This series fixes two resource leaks in the cadence-quadspi driver's
> probe error path and remove callback.

This doesn't apply against current code, please check and resend.

> base-commit: 52a355b23cd2dd77b683ed1a1bbe2b7408bd9c74

That's v6.12, that's rather ancient...

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

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

* Re: [PATCH 0/2] spi: cadence-quadspi: fix probe error path and remove
  2026-07-31 23:48 ` [PATCH 0/2] spi: cadence-quadspi: fix probe error path and remove Mark Brown
@ 2026-08-01 11:27   ` Diogo Ivo
  2026-08-01 15:54     ` Greg Kroah-Hartman
  0 siblings, 1 reply; 6+ messages in thread
From: Diogo Ivo @ 2026-08-01 11:27 UTC (permalink / raw)
  To: Mark Brown
  Cc: Matthew Gerlach, Khairul Anuar Romli, Greg Kroah-Hartman,
	Dan Carpenter, miquel.raynal, thomas.petazzoni, Pascal EBERHARD,
	linux-spi, linux-kernel, stable

Hi Mark,

On 8/1/26 1:48 AM, Mark Brown wrote:
> On Fri, Jul 31, 2026 at 12:53:45PM +0200, Diogo Ivo (Schneider Electric) wrote:
>> This series fixes two resource leaks in the cadence-quadspi driver's
>> probe error path and remove callback.
> 
> This doesn't apply against current code, please check and resend.

This series is meant to be applied only on the stable trees, as there
was a backport there that broke probing in certain scenarios. I should
have mentioned this more clearly in the cover letter, apologies for the
noise. If I need to resend explicitly mentioning which stable trees this
patch should be applied to let me know and I'll happily do it.

>> base-commit: 52a355b23cd2dd77b683ed1a1bbe2b7408bd9c74
> 
> That's v6.12, that's rather ancient...

Best regards,
Diogo

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

* Re: [PATCH 0/2] spi: cadence-quadspi: fix probe error path and remove
  2026-08-01 11:27   ` Diogo Ivo
@ 2026-08-01 15:54     ` Greg Kroah-Hartman
  0 siblings, 0 replies; 6+ messages in thread
From: Greg Kroah-Hartman @ 2026-08-01 15:54 UTC (permalink / raw)
  To: Diogo Ivo
  Cc: Mark Brown, Matthew Gerlach, Khairul Anuar Romli, Dan Carpenter,
	miquel.raynal, thomas.petazzoni, Pascal EBERHARD, linux-spi,
	linux-kernel, stable

On Sat, Aug 01, 2026 at 01:27:10PM +0200, Diogo Ivo wrote:
> Hi Mark,
> 
> On 8/1/26 1:48 AM, Mark Brown wrote:
> > On Fri, Jul 31, 2026 at 12:53:45PM +0200, Diogo Ivo (Schneider Electric) wrote:
> > > This series fixes two resource leaks in the cadence-quadspi driver's
> > > probe error path and remove callback.
> > 
> > This doesn't apply against current code, please check and resend.
> 
> This series is meant to be applied only on the stable trees, as there
> was a backport there that broke probing in certain scenarios. I should
> have mentioned this more clearly in the cover letter, apologies for the
> noise. If I need to resend explicitly mentioning which stable trees this
> patch should be applied to let me know and I'll happily do it.

Please do, as I'm confused :)

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

end of thread, other threads:[~2026-08-01 15:54 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-31 10:53 [PATCH 0/2] spi: cadence-quadspi: fix probe error path and remove Diogo Ivo (Schneider Electric)
2026-07-31 10:53 ` [PATCH 1/2] spi: cadence-quadspi: fix runtime pm cleanup on probe failure/unbind Diogo Ivo (Schneider Electric)
2026-07-31 10:53 ` [PATCH 2/2] spi: cadence-quadspi: release DMA channel on probe failure Diogo Ivo (Schneider Electric)
2026-07-31 23:48 ` [PATCH 0/2] spi: cadence-quadspi: fix probe error path and remove Mark Brown
2026-08-01 11:27   ` Diogo Ivo
2026-08-01 15:54     ` Greg Kroah-Hartman

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