[PATCH] spi: nxp-fspi: fix runtime PM cleanup on probe failure

Jiawen Liu <[email protected]>
Newsgroups dev.linux.lists.imx,org.kernel.vger.linux-kernel,org.kernel.vger.linux-spi
Message-ID <[email protected]>
nxp_fspi_probe() enables runtime PM before calling pm_runtime_get_sync()
to bring the controller clock on for register initialization.

If pm_runtime_get_sync() fails, the function currently returns immediately.
That leaves runtime PM enabled and leaves the usage counter incremented.
Clean up the failed get with pm_runtime_put_noidle() and disable runtime PM
before returning the error.

Signed-off-by: Jiawen Liu <[email protected]>
---
 drivers/spi/spi-nxp-fspi.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/drivers/spi/spi-nxp-fspi.c b/drivers/spi/spi-nxp-fspi.c
index 1e36ae084dd8..c6037f3209c5 100644
--- a/drivers/spi/spi-nxp-fspi.c
+++ b/drivers/spi/spi-nxp-fspi.c
@@ -1352,7 +1352,7 @@ static int nxp_fspi_probe(struct platform_device *pdev)
 	/* enable clock */
 	ret = pm_runtime_get_sync(f->dev);
 	if (ret < 0)
-		return dev_err_probe(dev, ret, "Failed to enable clock");
+		goto err_pm_runtime;
 
 	/* Clear potential interrupts */
 	reg = fspi_readl(f, f->iobase + FSPI_INTR);
@@ -1389,6 +1389,13 @@ static int nxp_fspi_probe(struct platform_device *pdev)
 		return ret;
 
 	return devm_spi_register_controller(&pdev->dev, ctlr);
+
+err_pm_runtime:
+	pm_runtime_put_noidle(dev);
+	pm_runtime_dont_use_autosuspend(dev);
+	pm_runtime_disable(dev);
+
+	return dev_err_probe(dev, ret, "Failed to enable clock");
 }
 
 static int nxp_fspi_runtime_suspend(struct device *dev)
-- 
2.34.1
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.