Skip to content

Commit 5101306

Browse files
leitaogregkh
authored andcommitted
spi: tegra210-quad: Move curr_xfer read inside spinlock
[ Upstream commit ef13ba3 ] Move the assignment of the transfer pointer from curr_xfer inside the spinlock critical section in both handle_cpu_based_xfer() and handle_dma_based_xfer(). Previously, curr_xfer was read before acquiring the lock, creating a window where the timeout path could clear curr_xfer between reading it and using it. By moving the read inside the lock, the handlers are guaranteed to see a consistent value that cannot be modified by the timeout path. Fixes: 921fc18 ("spi: tegra210-quad: Add support for Tegra210 QSPI controller") Signed-off-by: Breno Leitao <[email protected]> Acked-by: Thierry Reding <[email protected]> Tested-by: Jon Hunter <[email protected]> Acked-by: Jon Hunter <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Mark Brown <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent e1777c4 commit 5101306

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

drivers/spi/spi-tegra210-quad.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1376,10 +1376,11 @@ static int tegra_qspi_transfer_one_message(struct spi_controller *host,
13761376

13771377
static irqreturn_t handle_cpu_based_xfer(struct tegra_qspi *tqspi)
13781378
{
1379-
struct spi_transfer *t = tqspi->curr_xfer;
1379+
struct spi_transfer *t;
13801380
unsigned long flags;
13811381

13821382
spin_lock_irqsave(&tqspi->lock, flags);
1383+
t = tqspi->curr_xfer;
13831384

13841385
if (tqspi->tx_status || tqspi->rx_status) {
13851386
tegra_qspi_handle_error(tqspi);
@@ -1410,7 +1411,7 @@ static irqreturn_t handle_cpu_based_xfer(struct tegra_qspi *tqspi)
14101411

14111412
static irqreturn_t handle_dma_based_xfer(struct tegra_qspi *tqspi)
14121413
{
1413-
struct spi_transfer *t = tqspi->curr_xfer;
1414+
struct spi_transfer *t;
14141415
unsigned int total_fifo_words;
14151416
unsigned long flags;
14161417
long wait_status;
@@ -1449,6 +1450,7 @@ static irqreturn_t handle_dma_based_xfer(struct tegra_qspi *tqspi)
14491450
}
14501451

14511452
spin_lock_irqsave(&tqspi->lock, flags);
1453+
t = tqspi->curr_xfer;
14521454

14531455
if (num_errors) {
14541456
tegra_qspi_dma_unmap_xfer(tqspi, t);

0 commit comments

Comments
 (0)