]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
spi: imx: fix use-after-free on unbind
authorJohan Hovold <johan@kernel.org>
Tue, 24 Mar 2026 08:23:22 +0000 (09:23 +0100)
committerMark Brown <broonie@kernel.org>
Tue, 24 Mar 2026 14:25:47 +0000 (14:25 +0000)
The SPI subsystem frees the controller and any subsystem allocated
driver data as part of deregistration (unless the allocation is device
managed).

Take another reference before deregistering the controller so that the
driver data is not freed until the driver is done with it.

Fixes: 307c897db762 ("spi: spi-imx: replace struct spi_imx_data::bitbang by pointer to struct spi_controller")
Cc: stable@vger.kernel.org # 5.19
Acked-by: Marc Kleine-Budde <mkl@pengutronix.de>
Signed-off-by: Johan Hovold <johan@kernel.org>
Link: https://patch.msgid.link/20260324082326.901043-2-johan@kernel.org
Signed-off-by: Mark Brown <broonie@kernel.org>
drivers/spi/spi-imx.c

index 64c6c09e1e7bff110ce5986c442c7f8720da12e6..a8d90c86a8a11daaa0dab0656eed02acdc21ed35 100644 (file)
@@ -2401,6 +2401,8 @@ static void spi_imx_remove(struct platform_device *pdev)
        struct spi_imx_data *spi_imx = spi_controller_get_devdata(controller);
        int ret;
 
+       spi_controller_get(controller);
+
        spi_unregister_controller(controller);
 
        ret = pm_runtime_get_sync(spi_imx->dev);
@@ -2414,6 +2416,8 @@ static void spi_imx_remove(struct platform_device *pdev)
        pm_runtime_disable(spi_imx->dev);
 
        spi_imx_sdma_exit(spi_imx);
+
+       spi_controller_put(controller);
 }
 
 static int spi_imx_runtime_resume(struct device *dev)