Skip to content

Commit 3bc293d

Browse files
leitaogregkh
authored andcommitted
spi: tegra210-quad: Protect curr_xfer in tegra_qspi_combined_seq_xfer
[ Upstream commit bf4528a ] The curr_xfer field is read by the IRQ handler without holding the lock to check if a transfer is in progress. When clearing curr_xfer in the combined sequence transfer loop, protect it with the spinlock to prevent a race with the interrupt handler. Protect the curr_xfer clearing at the exit path of tegra_qspi_combined_seq_xfer() with the spinlock to prevent a race with the interrupt handler that reads this field. Without this protection, the IRQ handler could read a partially updated curr_xfer value, leading to NULL pointer dereference or use-after-free. Fixes: b4e002d ("spi: tegra210-quad: Fix timeout handling") Signed-off-by: Breno Leitao <[email protected]> Tested-by: Jon Hunter <[email protected]> Acked-by: Jon Hunter <[email protected]> Acked-by: Thierry Reding <[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 2d3c012 commit 3bc293d

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

drivers/spi/spi-tegra210-quad.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1089,6 +1089,7 @@ static int tegra_qspi_combined_seq_xfer(struct tegra_qspi *tqspi,
10891089
u32 address_value = 0;
10901090
u32 cmd_config = 0, addr_config = 0;
10911091
u8 cmd_value = 0, val = 0;
1092+
unsigned long flags;
10921093

10931094
/* Enable Combined sequence mode */
10941095
val = tegra_qspi_readl(tqspi, QSPI_GLOBAL_CONFIG);
@@ -1207,13 +1208,17 @@ static int tegra_qspi_combined_seq_xfer(struct tegra_qspi *tqspi,
12071208
tegra_qspi_transfer_end(spi);
12081209
spi_transfer_delay_exec(xfer);
12091210
}
1211+
spin_lock_irqsave(&tqspi->lock, flags);
12101212
tqspi->curr_xfer = NULL;
1213+
spin_unlock_irqrestore(&tqspi->lock, flags);
12111214
transfer_phase++;
12121215
}
12131216
ret = 0;
12141217

12151218
exit:
1219+
spin_lock_irqsave(&tqspi->lock, flags);
12161220
tqspi->curr_xfer = NULL;
1221+
spin_unlock_irqrestore(&tqspi->lock, flags);
12171222
msg->status = ret;
12181223

12191224
return ret;

0 commit comments

Comments
 (0)