Skip to content

Commit 6fd4461

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 <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-4-6d2115e4f387@debian.org Signed-off-by: Mark Brown <broonie@kernel.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent f5a8a27 commit 6fd4461

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
@@ -1064,6 +1064,7 @@ static int tegra_qspi_combined_seq_xfer(struct tegra_qspi *tqspi,
10641064
u32 address_value = 0;
10651065
u32 cmd_config = 0, addr_config = 0;
10661066
u8 cmd_value = 0, val = 0;
1067+
unsigned long flags;
10671068

10681069
/* Enable Combined sequence mode */
10691070
val = tegra_qspi_readl(tqspi, QSPI_GLOBAL_CONFIG);
@@ -1176,13 +1177,17 @@ static int tegra_qspi_combined_seq_xfer(struct tegra_qspi *tqspi,
11761177
tegra_qspi_transfer_end(spi);
11771178
spi_transfer_delay_exec(xfer);
11781179
}
1180+
spin_lock_irqsave(&tqspi->lock, flags);
11791181
tqspi->curr_xfer = NULL;
1182+
spin_unlock_irqrestore(&tqspi->lock, flags);
11801183
transfer_phase++;
11811184
}
11821185
ret = 0;
11831186

11841187
exit:
1188+
spin_lock_irqsave(&tqspi->lock, flags);
11851189
tqspi->curr_xfer = NULL;
1190+
spin_unlock_irqrestore(&tqspi->lock, flags);
11861191
msg->status = ret;
11871192

11881193
return ret;

0 commit comments

Comments
 (0)