public inbox for stable@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/6] spi: cadence-quadspi: fix runtime pm disable imbalance on probe failure
       [not found] <20260421125354.1534871-1-johan@kernel.org>
@ 2026-04-21 12:53 ` Johan Hovold
  2026-04-22  8:27   ` Miquel Raynal
  2026-04-21 12:53 ` [PATCH 2/6] spi: cadence-quadspi: fix clock " Johan Hovold
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 5+ messages in thread
From: Johan Hovold @ 2026-04-21 12:53 UTC (permalink / raw)
  To: Mark Brown
  Cc: Miquel Raynal, Anurag Dutta, Apurva Nandan, Dhruva Gole,
	linux-spi, linux-kernel, Johan Hovold, stable

A recent attempt to fix the probe error handling introduced a runtime PM
disable depth imbalance by incorrectly disabling runtime PM on early
failures (e.g. probe deferral).

Fixes: f18c8cfa4f1a ("spi: cadence-qspi: Fix probe error path and remove")
Cc: stable@vger.kernel.org	# 7.0
Cc: Miquel Raynal (Schneider Electric) <miquel.raynal@bootlin.com>
Signed-off-by: Johan Hovold <johan@kernel.org>
---
 drivers/spi/spi-cadence-quadspi.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/drivers/spi/spi-cadence-quadspi.c b/drivers/spi/spi-cadence-quadspi.c
index 50ef65fc5ded..5040e4e1cce0 100644
--- a/drivers/spi/spi-cadence-quadspi.c
+++ b/drivers/spi/spi-cadence-quadspi.c
@@ -1871,7 +1871,7 @@ static int cqspi_probe(struct platform_device *pdev)
 	ret = clk_bulk_prepare_enable(CLK_QSPI_NUM, cqspi->clks);
 	if (ret) {
 		dev_err(dev, "Cannot enable QSPI clocks.\n");
-		goto disable_rpm;
+		return ret;
 	}
 
 	/* Obtain QSPI reset control */
@@ -1981,7 +1981,7 @@ static int cqspi_probe(struct platform_device *pdev)
 		ret = cqspi_request_mmap_dma(cqspi);
 		if (ret == -EPROBE_DEFER) {
 			dev_err_probe(&pdev->dev, ret, "Failed to request mmap DMA\n");
-			goto disable_controller;
+			goto disable_rpm;
 		}
 	}
 
@@ -1999,14 +1999,13 @@ static int cqspi_probe(struct platform_device *pdev)
 release_dma_chan:
 	if (cqspi->rx_chan)
 		dma_release_channel(cqspi->rx_chan);
-disable_controller:
+disable_rpm:
+	if (!(ddata && (ddata->quirks & CQSPI_DISABLE_RUNTIME_PM)))
+		pm_runtime_disable(dev);
 	cqspi_controller_enable(cqspi, 0);
 disable_clks:
 	if (pm_runtime_get_sync(&pdev->dev) >= 0)
 		clk_bulk_disable_unprepare(CLK_QSPI_NUM, cqspi->clks);
-disable_rpm:
-	if (!(ddata && (ddata->quirks & CQSPI_DISABLE_RUNTIME_PM)))
-		pm_runtime_disable(dev);
 
 	return ret;
 }
-- 
2.52.0


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

* [PATCH 2/6] spi: cadence-quadspi: fix clock imbalance on probe failure
       [not found] <20260421125354.1534871-1-johan@kernel.org>
  2026-04-21 12:53 ` [PATCH 1/6] spi: cadence-quadspi: fix runtime pm disable imbalance on probe failure Johan Hovold
@ 2026-04-21 12:53 ` Johan Hovold
  2026-04-21 12:53 ` [PATCH 3/6] spi: cadence-quadspi: fix unclocked access on unbind Johan Hovold
  2026-04-21 12:53 ` [PATCH 4/6] spi: cadence-quadspi: fix runtime pm and clock imbalance " Johan Hovold
  3 siblings, 0 replies; 5+ messages in thread
From: Johan Hovold @ 2026-04-21 12:53 UTC (permalink / raw)
  To: Mark Brown
  Cc: Miquel Raynal, Anurag Dutta, Apurva Nandan, Dhruva Gole,
	linux-spi, linux-kernel, Johan Hovold, stable

Drop the bogus runtime PM get on probe failures that was never needed
and that leaks a usage count reference while preventing the clocks from
being disabled (as runtime PM has not yet been enabled).

Fixes: 1889dd208197 ("spi: cadence-quadspi: Fix clock disable on probe failure path")
Cc: stable@vger.kernel.org	# 6.19
Cc: Anurag Dutta <a-dutta@ti.com>
Signed-off-by: Johan Hovold <johan@kernel.org>
---
 drivers/spi/spi-cadence-quadspi.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/spi/spi-cadence-quadspi.c b/drivers/spi/spi-cadence-quadspi.c
index 5040e4e1cce0..b79f48f2420c 100644
--- a/drivers/spi/spi-cadence-quadspi.c
+++ b/drivers/spi/spi-cadence-quadspi.c
@@ -2004,8 +2004,7 @@ static int cqspi_probe(struct platform_device *pdev)
 		pm_runtime_disable(dev);
 	cqspi_controller_enable(cqspi, 0);
 disable_clks:
-	if (pm_runtime_get_sync(&pdev->dev) >= 0)
-		clk_bulk_disable_unprepare(CLK_QSPI_NUM, cqspi->clks);
+	clk_bulk_disable_unprepare(CLK_QSPI_NUM, cqspi->clks);
 
 	return ret;
 }
-- 
2.52.0


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

* [PATCH 3/6] spi: cadence-quadspi: fix unclocked access on unbind
       [not found] <20260421125354.1534871-1-johan@kernel.org>
  2026-04-21 12:53 ` [PATCH 1/6] spi: cadence-quadspi: fix runtime pm disable imbalance on probe failure Johan Hovold
  2026-04-21 12:53 ` [PATCH 2/6] spi: cadence-quadspi: fix clock " Johan Hovold
@ 2026-04-21 12:53 ` Johan Hovold
  2026-04-21 12:53 ` [PATCH 4/6] spi: cadence-quadspi: fix runtime pm and clock imbalance " Johan Hovold
  3 siblings, 0 replies; 5+ messages in thread
From: Johan Hovold @ 2026-04-21 12:53 UTC (permalink / raw)
  To: Mark Brown
  Cc: Miquel Raynal, Anurag Dutta, Apurva Nandan, Dhruva Gole,
	linux-spi, linux-kernel, Johan Hovold, stable

Make sure that the controller is runtime resumed before disabling it
during driver unbind to avoid an unclocked register access.

This issue was flagged by Sashiko when reviewing a controller
deregistration fix.

Fixes: 0578a6dbfe75 ("spi: spi-cadence-quadspi: add runtime pm support")
Cc: stable@vger.kernel.org	# 6.7
Cc: Dhruva Gole <d-gole@ti.com>
Link: https://sashiko.dev/#/patchset/20260414134319.978196-1-johan%40kernel.org?part=2
Signed-off-by: Johan Hovold <johan@kernel.org>
---
 drivers/spi/spi-cadence-quadspi.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/drivers/spi/spi-cadence-quadspi.c b/drivers/spi/spi-cadence-quadspi.c
index b79f48f2420c..87dc14c53675 100644
--- a/drivers/spi/spi-cadence-quadspi.c
+++ b/drivers/spi/spi-cadence-quadspi.c
@@ -2028,14 +2028,13 @@ static void cqspi_remove(struct platform_device *pdev)
 	if (cqspi->rx_chan)
 		dma_release_channel(cqspi->rx_chan);
 
-	cqspi_controller_enable(cqspi, 0);
-
-
 	if (!(ddata && (ddata->quirks & CQSPI_DISABLE_RUNTIME_PM)))
 		ret = pm_runtime_get_sync(&pdev->dev);
 
-	if (ret >= 0)
+	if (ret >= 0) {
+		cqspi_controller_enable(cqspi, 0);
 		clk_bulk_disable_unprepare(CLK_QSPI_NUM, cqspi->clks);
+	}
 
 	if (!(ddata && (ddata->quirks & CQSPI_DISABLE_RUNTIME_PM))) {
 		pm_runtime_put_sync(&pdev->dev);
-- 
2.52.0


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

* [PATCH 4/6] spi: cadence-quadspi: fix runtime pm and clock imbalance on unbind
       [not found] <20260421125354.1534871-1-johan@kernel.org>
                   ` (2 preceding siblings ...)
  2026-04-21 12:53 ` [PATCH 3/6] spi: cadence-quadspi: fix unclocked access on unbind Johan Hovold
@ 2026-04-21 12:53 ` Johan Hovold
  3 siblings, 0 replies; 5+ messages in thread
From: Johan Hovold @ 2026-04-21 12:53 UTC (permalink / raw)
  To: Mark Brown
  Cc: Miquel Raynal, Anurag Dutta, Apurva Nandan, Dhruva Gole,
	linux-spi, linux-kernel, Johan Hovold, stable

Make sure to balance the runtime PM usage count before returning on
probe failure (to allow the controller to suspend after a probe
deferral) and to only drop the usage count on driver unbind to avoid a
clock disable imbalance.

Also restore the autosuspend setting.

Fixes: 0578a6dbfe75 ("spi: spi-cadence-quadspi: add runtime pm support")
Cc: stable@vger.kernel.org	# 6.7
Cc: Dhruva Gole <d-gole@ti.com>
Signed-off-by: Johan Hovold <johan@kernel.org>
---
 drivers/spi/spi-cadence-quadspi.c | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/drivers/spi/spi-cadence-quadspi.c b/drivers/spi/spi-cadence-quadspi.c
index 87dc14c53675..1b0d6186c7ef 100644
--- a/drivers/spi/spi-cadence-quadspi.c
+++ b/drivers/spi/spi-cadence-quadspi.c
@@ -1864,10 +1864,6 @@ static int cqspi_probe(struct platform_device *pdev)
 	if (irq < 0)
 		return -ENXIO;
 
-	ret = pm_runtime_set_active(dev);
-	if (ret)
-		return ret;
-
 	ret = clk_bulk_prepare_enable(CLK_QSPI_NUM, cqspi->clks);
 	if (ret) {
 		dev_err(dev, "Cannot enable QSPI clocks.\n");
@@ -1966,10 +1962,11 @@ static int cqspi_probe(struct platform_device *pdev)
 	cqspi->sclk = 0;
 
 	if (!(ddata && (ddata->quirks & CQSPI_DISABLE_RUNTIME_PM))) {
-		pm_runtime_enable(dev);
 		pm_runtime_set_autosuspend_delay(dev, CQSPI_AUTOSUSPEND_TIMEOUT);
 		pm_runtime_use_autosuspend(dev);
 		pm_runtime_get_noresume(dev);
+		pm_runtime_set_active(dev);
+		pm_runtime_enable(dev);
 	}
 
 	host->num_chipselect = cqspi->num_chipselect;
@@ -2000,8 +1997,12 @@ static int cqspi_probe(struct platform_device *pdev)
 	if (cqspi->rx_chan)
 		dma_release_channel(cqspi->rx_chan);
 disable_rpm:
-	if (!(ddata && (ddata->quirks & CQSPI_DISABLE_RUNTIME_PM)))
+	if (!(ddata && (ddata->quirks & CQSPI_DISABLE_RUNTIME_PM))) {
 		pm_runtime_disable(dev);
+		pm_runtime_set_suspended(dev);
+		pm_runtime_put_noidle(dev);
+		pm_runtime_dont_use_autosuspend(dev);
+	}
 	cqspi_controller_enable(cqspi, 0);
 disable_clks:
 	clk_bulk_disable_unprepare(CLK_QSPI_NUM, cqspi->clks);
@@ -2037,8 +2038,10 @@ static void cqspi_remove(struct platform_device *pdev)
 	}
 
 	if (!(ddata && (ddata->quirks & CQSPI_DISABLE_RUNTIME_PM))) {
-		pm_runtime_put_sync(&pdev->dev);
 		pm_runtime_disable(&pdev->dev);
+		pm_runtime_set_suspended(&pdev->dev);
+		pm_runtime_put_noidle(&pdev->dev);
+		pm_runtime_dont_use_autosuspend(&pdev->dev);
 	}
 }
 
-- 
2.52.0


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

* Re: [PATCH 1/6] spi: cadence-quadspi: fix runtime pm disable imbalance on probe failure
  2026-04-21 12:53 ` [PATCH 1/6] spi: cadence-quadspi: fix runtime pm disable imbalance on probe failure Johan Hovold
@ 2026-04-22  8:27   ` Miquel Raynal
  0 siblings, 0 replies; 5+ messages in thread
From: Miquel Raynal @ 2026-04-22  8:27 UTC (permalink / raw)
  To: Johan Hovold
  Cc: Mark Brown, Anurag Dutta, Apurva Nandan, Dhruva Gole, linux-spi,
	linux-kernel, stable

Hi,

On 21/04/2026 at 14:53:49 +02, Johan Hovold <johan@kernel.org> wrote:

> A recent attempt to fix the probe error handling introduced a runtime PM
> disable depth imbalance by incorrectly disabling runtime PM on early
> failures (e.g. probe deferral).
>
> Fixes: f18c8cfa4f1a ("spi: cadence-qspi: Fix probe error path and remove")
> Cc: stable@vger.kernel.org	# 7.0
> Cc: Miquel Raynal (Schneider Electric) <miquel.raynal@bootlin.com>
> Signed-off-by: Johan Hovold <johan@kernel.org>

Reading it again, I probably got confused by the impact of
pm_runtime_set_active(), what you propose looks correct.

Reviewed-by: Miquel Raynal <miquel.raynal@bootlin.com>

Thanks,
Miquèl

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

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

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20260421125354.1534871-1-johan@kernel.org>
2026-04-21 12:53 ` [PATCH 1/6] spi: cadence-quadspi: fix runtime pm disable imbalance on probe failure Johan Hovold
2026-04-22  8:27   ` Miquel Raynal
2026-04-21 12:53 ` [PATCH 2/6] spi: cadence-quadspi: fix clock " Johan Hovold
2026-04-21 12:53 ` [PATCH 3/6] spi: cadence-quadspi: fix unclocked access on unbind Johan Hovold
2026-04-21 12:53 ` [PATCH 4/6] spi: cadence-quadspi: fix runtime pm and clock imbalance " Johan Hovold

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