Skip to content

Commit 44ae47f

Browse files
committed
spi: spi-imx: spi_imx_transfer_one(): check for DMA transfer first
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2071848 Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2122415 commit e85e9e0 Author: Marc Kleine-Budde <mkl@pengutronix.de> Date: Wed, 16 Nov 2022 17:49:30 +0100 The SPI framework checks for each transfer (with the struct spi_controller::can_dma callback) whether the driver wants to use DMA for the transfer. If the driver returns true, the SPI framework will map the transfer's data to the device, start the actual transfer and map the data back. In commit 07e7593 ("spi: spi-imx: add PIO polling support") the spi-imx driver's spi_imx_transfer_one() function was extended. If the estimated duration of a transfer does not exceed a configurable duration, a polling transfer function is used. This check happens before checking if the driver decided earlier for a DMA transfer. If spi_imx_can_dma() decided to use a DMA transfer, and the user configured a big maximum polling duration, a polling transfer will be used. The DMA unmap after the transfer destroys the transferred data. To fix this problem check in spi_imx_transfer_one() if the driver decided for DMA transfer first, then check the limits for a polling transfer. Fixes: 07e7593 ("spi: spi-imx: add PIO polling support") Link: https://lore.kernel.org/all/20221111003032.82371-1-festevam@gmail.com Reported-by: Frieder Schrempf <frieder.schrempf@kontron.de> Reported-by: Fabio Estevam <festevam@gmail.com> Tested-by: Fabio Estevam <festevam@gmail.com> Cc: David Jander <david@protonic.nl> Cc: stable@vger.kernel.org Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de> Tested-by: Frieder Schrempf <frieder.schrempf@kontron.de> Reviewed-by: Frieder Schrempf <frieder.schrempf@kontron.de> Link: https://lore.kernel.org/r/20221116164930.855362-1-mkl@pengutronix.de Signed-off-by: Mark Brown <broonie@kernel.org> Signed-off-by: Mark Salter <msalter@redhat.com>
1 parent 885c25e commit 44ae47f

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

drivers/spi/spi-imx.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1606,6 +1606,13 @@ static int spi_imx_transfer_one(struct spi_controller *controller,
16061606
if (spi_imx->slave_mode)
16071607
return spi_imx_pio_transfer_slave(spi, transfer);
16081608

1609+
/*
1610+
* If we decided in spi_imx_can_dma() that we want to do a DMA
1611+
* transfer, the SPI transfer has already been mapped, so we
1612+
* have to do the DMA transfer here.
1613+
*/
1614+
if (spi_imx->usedma)
1615+
return spi_imx_dma_transfer(spi_imx, transfer);
16091616
/*
16101617
* Calculate the estimated time in us the transfer runs. Find
16111618
* the number of Hz per byte per polling limit.
@@ -1617,9 +1624,6 @@ static int spi_imx_transfer_one(struct spi_controller *controller,
16171624
if (transfer->len < byte_limit)
16181625
return spi_imx_poll_transfer(spi, transfer);
16191626

1620-
if (spi_imx->usedma)
1621-
return spi_imx_dma_transfer(spi_imx, transfer);
1622-
16231627
return spi_imx_pio_transfer(spi, transfer);
16241628
}
16251629

0 commit comments

Comments
 (0)