FAILED: patch "[PATCH] spi: pxa2xx: Fix controller unregister order" failed to apply to 4.19-stable tree
[email protected]
maintainerThe patch below does not apply to the 4.19-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From 32e5b57232c0411e7dea96625c415510430ac079 Mon Sep 17 00:00:00 2001
From: Lukas Wunner <[email protected]>
Date: Mon, 25 May 2020 14:25:02 +0200
Subject: [PATCH] spi: pxa2xx: Fix controller unregister order
The PXA2xx SPI driver uses devm_spi_register_controller() on bind. As a consequence, on unbind, __device_release_driver() first invokes pxa2xx_spi_remove() before unregistering the SPI controller via devres_release_all().
This order is incorrect: pxa2xx_spi_remove() disables the chip, rendering the SPI bus inaccessible even though the SPI controller is still registered. When the SPI controller is subsequently unregistered, it unbinds all its slave devices. Because their drivers cannot access the SPI bus, e.g. to quiesce interrupts, the slave devices may be left in an improper state.
As a rule, devm_spi_register_controller() must not be used if the ->remove() hook performs teardown steps which shall be performed after unregistering the controller and specifically after unbinding of slaves.
Fix by reverting to the non-devm variant of spi_register_controller().
An alternative approach would be to use device-managed functions for all steps in pxa2xx_spi_remove(), e.g. by calling devm_add_action_or_reset() on probe. However that approach would add more LoC to the driver and it wouldn't lend itself as well to backporting to stable.
The improper use of devm_spi_register_controller() was introduced in 2013 by commit a807fcd090d6 ("spi: pxa2xx: use devm_spi_register_master()"), but all earlier versions of the driver going back to 2006 were likewise broken because they invoked spi_unregister_master() at the end of pxa2xx_spi_remove(), rather than at the beginning.
drivers/spi/spi-pxa2xx.c +3 -1
@@ -1884,7 +1884,7 @@ static int pxa2xx_spi_probe(struct platform_device *pdev)/* Register with the SPI framework */ platform_set_drvdata (pdev, drv_data); - status =devm_spi_register_controller (&pdev->dev, controller); + status =spi_register_controller (controller);if (status !=0 ) {dev_err (&pdev->dev,"problem registering spi controller\n" ); goto out_error_pm_runtime_enabled;
@@ -1916,6 +1916,8 @@ static int pxa2xx_spi_remove(struct platform_device *pdev)pm_runtime_get_sync (&pdev->dev); +spi_unregister_controller (drv_data->controller); +/* Disable the SSP at the peripheral and SOC level */ pxa2xx_spi_write (drv_data,SSCR0 ,0 );clk_disable_unprepare (ssp->clk);
Sasha Levin
maintainerQuoted 46 lines · On Mon, Jun 15, 2020 at 05:21:18PM +0200, [email protected] wrote:
The patch below does not apply to the 4.19-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From
32e5b57232c0411e7dea96625c415510430ac079Mon Sep 17 00:00:00 2001
From: Lukas Wunner <[email protected]>
Date: Mon, 25 May 2020 14:25:02 +0200
Subject: [PATCH] spi: pxa2xx: Fix controller unregister orderThe PXA2xx SPI driver uses
devm_spi_register_controller()on bind. As a consequence, on unbind,__device_release_driver()first invokespxa2xx_spi_remove()before unregistering the SPI controller viadevres_release_all().This order is incorrect:
pxa2xx_spi_remove()disables the chip, rendering the SPI bus inaccessible even though the SPI controller is still registered. When the SPI controller is subsequently unregistered, it unbinds all its slave devices. Because their drivers cannot access the SPI bus, e.g. to quiesce interrupts, the slave devices may be left in an improper state.As a rule,
devm_spi_register_controller()must not be used if the ->remove() hook performs teardown steps which shall be performed after unregistering the controller and specifically after unbinding of slaves.Fix by reverting to the non-devm variant of
spi_register_controller().An alternative approach would be to use device-managed functions for all steps in
pxa2xx_spi_remove(), e.g. by callingdevm_add_action_or_reset()on probe. However that approach would add more LoC to the driver and it wouldn't lend itself as well to backporting to stable.The improper use of
devm_spi_register_controller()was introduced in 2013 by commita807fcd090d6("spi: pxa2xx: usedevm_spi_register_master()"), but all earlier versions of the driver going back to 2006 were likewise broken because they invokedspi_unregister_master()at the end ofpxa2xx_spi_remove(), rather than at the beginning.
Quoted 8 lines
Fixes e0c9905e87ac ("[PATCH] SPI: add PXA2xx SSP SPI Driver")Signed-off-by Lukas Wunner <[email protected]>Reviewed-by Andy Shevchenko <[email protected]>Cc [email protected] # v2.6.17+Cc Tsuchiya Yuto <[email protected]>Link https://lore.kernel.org/r/834c446b1cf3284d2660f1bee1ebe3e737cd02a9.1590408496.git.lukas@wunner.de open hereSigned-off-by Mark Brown <[email protected]>
more work around master -> controller rename. Queued for 4.19, 4.14, 4.9, and 4.4.
Signature · 2 lines
Thanks, Sasha