Skip to content

Commit 9dd277f

Browse files
l1kbroonie
authored andcommitted
spi: bcm2835: Fix controller unregister order
The BCM2835 SPI driver uses devm_spi_register_controller() on bind. As a consequence, on unbind, __device_release_driver() first invokes bcm2835_spi_remove() before unregistering the SPI controller via devres_release_all(). This order is incorrect: bcm2835_spi_remove() tears down the DMA channels and turns off the SPI controller, including its interrupts and clock. The SPI controller is thus no longer usable. When the SPI controller is subsequently unregistered, it unbinds all its slave devices. If their drivers need to access the SPI bus, e.g. to quiesce their interrupts, unbinding will fail. As a rule, devm_spi_register_controller() must not be used if the ->remove() hook performs teardown steps which shall be performed after unbinding of slaves. Fix by using the non-devm variant spi_register_controller(). Note that the struct spi_controller as well as the driver-private data are not freed until after bcm2835_spi_remove() has finished, so accessing them is safe. Fixes: 247263d ("spi: bcm2835: use devm_spi_register_master()") Signed-off-by: Lukas Wunner <[email protected]> Cc: [email protected] # v3.13+ Link: https://lore.kernel.org/r/2397dd70cdbe95e0bc4da2b9fca0f31cb94e5aed.1589557526.git.lukas@wunner.de Signed-off-by: Mark Brown <[email protected]>
1 parent 8485567 commit 9dd277f

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

drivers/spi/spi-bcm2835.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1347,7 +1347,7 @@ static int bcm2835_spi_probe(struct platform_device *pdev)
13471347
goto out_dma_release;
13481348
}
13491349

1350-
err = devm_spi_register_controller(&pdev->dev, ctlr);
1350+
err = spi_register_controller(ctlr);
13511351
if (err) {
13521352
dev_err(&pdev->dev, "could not register SPI controller: %d\n",
13531353
err);
@@ -1374,6 +1374,8 @@ static int bcm2835_spi_remove(struct platform_device *pdev)
13741374

13751375
bcm2835_debugfs_remove(bs);
13761376

1377+
spi_unregister_controller(ctlr);
1378+
13771379
/* Clear FIFOs, and disable the HW block */
13781380
bcm2835_wr(bs, BCM2835_SPI_CS,
13791381
BCM2835_SPI_CS_CLEAR_RX | BCM2835_SPI_CS_CLEAR_TX);

0 commit comments

Comments
 (0)