]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
spi: cadence: fix unclocked access on unbind
authorJohan Hovold <johan@kernel.org>
Tue, 21 Apr 2026 12:36:12 +0000 (14:36 +0200)
committerMark Brown <broonie@kernel.org>
Sun, 26 Apr 2026 23:25:48 +0000 (08:25 +0900)
Make sure that the controller is runtime resumed before disabling it
during driver unbind to avoid unclocked register access and unbalanced
clock disable.

Also restore the autosuspend setting.

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

Fixes: d36ccd9f7ea4 ("spi: cadence: Runtime pm adaptation")
Cc: stable@vger.kernel.org # 4.7
Cc: Shubhrajyoti Datta <shubhrajyoti.datta@xilinx.com>
Link: https://sashiko.dev/#/patchset/20260414134319.978196-1-johan%40kernel.org?part=1
Signed-off-by: Johan Hovold <johan@kernel.org>
Link: https://patch.msgid.link/20260421123615.1533617-2-johan@kernel.org
Signed-off-by: Mark Brown <broonie@kernel.org>
drivers/spi/spi-cadence.c

index 08d7dabe818dc91a0ad2f0d4daeb618231b547a5..bf4a7cf6b1426b0555ee502bc2d0e4a319355bf0 100644 (file)
@@ -776,16 +776,23 @@ 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);
+       int ret = 0;
+
+       if (!spi_controller_is_target(ctlr))
+               ret = pm_runtime_get_sync(&pdev->dev);
 
        spi_controller_get(ctlr);
 
        spi_unregister_controller(ctlr);
 
-       cdns_spi_write(xspi, CDNS_SPI_ER, CDNS_SPI_ER_DISABLE);
+       if (ret >= 0)
+               cdns_spi_write(xspi, CDNS_SPI_ER, CDNS_SPI_ER_DISABLE);
 
        if (!spi_controller_is_target(ctlr)) {
                pm_runtime_disable(&pdev->dev);
                pm_runtime_set_suspended(&pdev->dev);
+               pm_runtime_put_noidle(&pdev->dev);
+               pm_runtime_dont_use_autosuspend(&pdev->dev);
        }
 
        spi_controller_put(ctlr);