[PATCH 2/2] spi: cadence-quadspi: Fix clock disable on probe failure path

Anurag Dutta posted 2 patches 1 month, 3 weeks ago
[PATCH 2/2] spi: cadence-quadspi: Fix clock disable on probe failure path
Posted by Anurag Dutta 1 month, 3 weeks ago
When cqspi_request_mmap_dma() returns -EPROBE_DEFER after runtime PM
is enabled, the error path calls clk_disable_unprepare() on an already
disabled clock, causing an imbalance.

Use pm_runtime_get_sync() to increment the usage counter and resume the
device. This prevents runtime_suspend() from being invoked and causing
a double clock disable.

Fixes: 140623410536 ("mtd: spi-nor: Add driver for Cadence Quad SPI Flash Controller")
Signed-off-by: Anurag Dutta <a-dutta@ti.com>
---
 drivers/spi/spi-cadence-quadspi.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/spi/spi-cadence-quadspi.c b/drivers/spi/spi-cadence-quadspi.c
index 7c1f742d95a6..f8823e83a622 100644
--- a/drivers/spi/spi-cadence-quadspi.c
+++ b/drivers/spi/spi-cadence-quadspi.c
@@ -2026,7 +2026,9 @@ static int cqspi_probe(struct platform_device *pdev)
 probe_reset_failed:
 	if (cqspi->is_jh7110)
 		cqspi_jh7110_disable_clk(pdev, cqspi);
-	clk_disable_unprepare(cqspi->clk);
+
+	if (pm_runtime_get_sync(&pdev->dev) >= 0)
+		clk_disable_unprepare(cqspi->clk);
 probe_clk_failed:
 	return ret;
 }
-- 
2.34.1
Re: [PATCH 2/2] spi: cadence-quadspi: Fix clock disable on probe failure path
Posted by Mark Brown 1 month, 3 weeks ago
On Fri, Dec 12, 2025 at 12:53:12PM +0530, Anurag Dutta wrote:
> When cqspi_request_mmap_dma() returns -EPROBE_DEFER after runtime PM
> is enabled, the error path calls clk_disable_unprepare() on an already
> disabled clock, causing an imbalance.
> 
> Use pm_runtime_get_sync() to increment the usage counter and resume the
> device. This prevents runtime_suspend() from being invoked and causing
> a double clock disable.

Thanks - this is working for me with a hack to trigger the issue,
hopefully others seeing the issue in real scenarios can confirm.
Re: [PATCH 2/2] spi: cadence-quadspi: Fix clock disable on probe failure path
Posted by Nishanth Menon 1 month, 3 weeks ago
On 17:44-20251212, Mark Brown wrote:
> On Fri, Dec 12, 2025 at 12:53:12PM +0530, Anurag Dutta wrote:
> > When cqspi_request_mmap_dma() returns -EPROBE_DEFER after runtime PM
> > is enabled, the error path calls clk_disable_unprepare() on an already
> > disabled clock, causing an imbalance.
> > 
> > Use pm_runtime_get_sync() to increment the usage counter and resume the
> > device. This prevents runtime_suspend() from being invoked and causing
> > a double clock disable.
> 
> Thanks - this is working for me with a hack to trigger the issue,
> hopefully others seeing the issue in real scenarios can confirm.

This seems to fix the warnings I had reported at least.

gist: https://gist.github.com/nmenon/f062ebcb51f97859e97c9716a27fa494

Tested-by: Nishanth Menon <nm@ti.com>


-- 
Regards,
Nishanth Menon
Key (0xDDB5849D1736249D) / Fingerprint: F8A2 8693 54EB 8232 17A3  1A34 DDB5 849D 1736 249D
https://ti.com/opensource