Skip to content

Commit bf4528a

Browse files
leitaobroonie
authored andcommitted
spi: tegra210-quad: Protect curr_xfer in tegra_qspi_combined_seq_xfer
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>
1 parent f5a4d7f commit bf4528a

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
@@ -1161,6 +1161,7 @@ static int tegra_qspi_combined_seq_xfer(struct tegra_qspi *tqspi,
11611161
u32 address_value = 0;
11621162
u32 cmd_config = 0, addr_config = 0;
11631163
u8 cmd_value = 0, val = 0;
1164+
unsigned long flags;
11641165

11651166
/* Enable Combined sequence mode */
11661167
val = tegra_qspi_readl(tqspi, QSPI_GLOBAL_CONFIG);
@@ -1264,13 +1265,17 @@ static int tegra_qspi_combined_seq_xfer(struct tegra_qspi *tqspi,
12641265
tegra_qspi_transfer_end(spi);
12651266
spi_transfer_delay_exec(xfer);
12661267
}
1268+
spin_lock_irqsave(&tqspi->lock, flags);
12671269
tqspi->curr_xfer = NULL;
1270+
spin_unlock_irqrestore(&tqspi->lock, flags);
12681271
transfer_phase++;
12691272
}
12701273
ret = 0;
12711274

12721275
exit:
1276+
spin_lock_irqsave(&tqspi->lock, flags);
12731277
tqspi->curr_xfer = NULL;
1278+
spin_unlock_irqrestore(&tqspi->lock, flags);
12741279
msg->status = ret;
12751280

12761281
return ret;

0 commit comments

Comments
 (0)