Skip to content

Commit ca8b19d

Browse files
l1kbroonie
authored andcommitted
spi: dw: Fix controller unregister order
The Designware SPI driver uses devm_spi_register_controller() on bind. As a consequence, on unbind, __device_release_driver() first invokes dw_spi_remove_host() before unregistering the SPI controller via devres_release_all(). This order is incorrect: dw_spi_remove_host() shuts down 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 dw_spi_remove_host(), 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. Fixes: 04f421e ("spi: dw: use managed resources") Signed-off-by: Lukas Wunner <[email protected]> Reviewed-by: Andy Shevchenko <[email protected]> Cc: [email protected] # v3.14+ Cc: Baruch Siach <[email protected]> Link: https://lore.kernel.org/r/3fff8cb8ae44a9893840d0688be15bb88c090a14.1590408496.git.lukas@wunner.de Signed-off-by: Mark Brown <[email protected]>
1 parent a2b02e4 commit ca8b19d

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

drivers/spi/spi-dw.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ int dw_spi_add_host(struct device *dev, struct dw_spi *dws)
526526
}
527527
}
528528

529-
ret = devm_spi_register_controller(dev, master);
529+
ret = spi_register_controller(master);
530530
if (ret) {
531531
dev_err(&master->dev, "problem registering spi master\n");
532532
goto err_dma_exit;
@@ -550,6 +550,8 @@ void dw_spi_remove_host(struct dw_spi *dws)
550550
{
551551
dw_spi_debugfs_remove(dws);
552552

553+
spi_unregister_controller(dws->master);
554+
553555
if (dws->dma_ops && dws->dma_ops->dma_exit)
554556
dws->dma_ops->dma_exit(dws);
555557

0 commit comments

Comments
 (0)