spi: atmel: fixed spin_lock usage inside atmel_spi_remove
authorRadu Pirea <radu.pirea@microchip.com>
Fri, 15 Dec 2017 15:40:17 +0000 (17:40 +0200)
committerSasha Levin <alexander.levin@microsoft.com>
Wed, 21 Mar 2018 03:49:44 +0000 (23:49 -0400)
[ Upstream commit 66e900a3d225575c8b48b59ae1fe74bb6e5a65cc ]

The only part of atmel_spi_remove which needs to be atomic is hardware
reset.

atmel_spi_stop_dma calls dma_terminate_all and this needs interrupts
enabled.
atmel_spi_release_dma calls dma_release_channel and dma_release_channel
locks a mutex inside of spin_lock.

So the call of these functions can't be inside a spin_lock.

Reported-by: Jia-Ju Bai <baijiaju1990@gmail.com>
Signed-off-by: Radu Pirea <radu.pirea@microchip.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
Signed-off-by: Sasha Levin <alexander.levin@microsoft.com>
drivers/spi/spi-atmel.c

index a2f40b1b222500eb53d14c681ab58f3d3c445af8..3fef713f693b1853e80433756902bd78dca3e1ce 100644 (file)
@@ -1423,12 +1423,12 @@ static int atmel_spi_remove(struct platform_device *pdev)
        pm_runtime_get_sync(&pdev->dev);
 
        /* reset the hardware and block queue progress */
-       spin_lock_irq(&as->lock);
        if (as->use_dma) {
                atmel_spi_stop_dma(as);
                atmel_spi_release_dma(as);
        }
 
+       spin_lock_irq(&as->lock);
        spi_writel(as, CR, SPI_BIT(SWRST));
        spi_writel(as, CR, SPI_BIT(SWRST)); /* AT91SAM9263 Rev B workaround */
        spi_readl(as, SR);