Skip to content

Commit f5a4d7f

Browse files
leitaobroonie
authored andcommitted
spi: tegra210-quad: Protect curr_xfer assignment in tegra_qspi_setup_transfer_one
When the timeout handler processes a completed transfer and signals completion, the transfer thread can immediately set up the next transfer and assign curr_xfer to point to it. If a delayed ISR from the previous transfer then runs, it checks if (!tqspi->curr_xfer) (currently without the lock also -- to be fixed soon) to detect stale interrupts, but this check passes because curr_xfer now points to the new transfer. The ISR then incorrectly processes the new transfer's context. Protect the curr_xfer assignment with the spinlock to ensure the ISR either sees NULL (and bails out) or sees the new value only after the assignment is complete. Fixes: 921fc18 ("spi: tegra210-quad: Add support for Tegra210 QSPI controller") Signed-off-by: Breno Leitao <leitao@debian.org> Tested-by: Jon Hunter <jonathanh@nvidia.com> Acked-by: Jon Hunter <jonathanh@nvidia.com> Acked-by: Thierry Reding <treding@nvidia.com> Link: https://patch.msgid.link/20260126-tegra_xfer-v2-3-6d2115e4f387@debian.org Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent ef13ba3 commit f5a4d7f

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

drivers/spi/spi-tegra210-quad.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -839,17 +839,20 @@ static u32 tegra_qspi_setup_transfer_one(struct spi_device *spi, struct spi_tran
839839
u32 command1, command2, speed = t->speed_hz;
840840
u8 bits_per_word = t->bits_per_word;
841841
u32 tx_tap = 0, rx_tap = 0;
842+
unsigned long flags;
842843
int req_mode;
843844

844845
if (!has_acpi_companion(tqspi->dev) && speed != tqspi->cur_speed) {
845846
clk_set_rate(tqspi->clk, speed);
846847
tqspi->cur_speed = speed;
847848
}
848849

850+
spin_lock_irqsave(&tqspi->lock, flags);
849851
tqspi->cur_pos = 0;
850852
tqspi->cur_rx_pos = 0;
851853
tqspi->cur_tx_pos = 0;
852854
tqspi->curr_xfer = t;
855+
spin_unlock_irqrestore(&tqspi->lock, flags);
853856

854857
if (is_first_of_msg) {
855858
tegra_qspi_mask_clear_irq(tqspi);

0 commit comments

Comments
 (0)