Unverified Commit bf4528ab authored by Breno Leitao's avatar Breno Leitao Committed by Mark Brown
Browse files

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: b4e002d8 ("spi: tegra210-quad: Fix timeout handling")
Signed-off-by: default avatarBreno Leitao <leitao@debian.org>
Tested-by: default avatarJon Hunter <jonathanh@nvidia.com>
Acked-by: default avatarJon Hunter <jonathanh@nvidia.com>
Acked-by: default avatarThierry Reding <treding@nvidia.com>
Link: https://patch.msgid.link/20260126-tegra_xfer-v2-4-6d2115e4f387@debian.org


Signed-off-by: default avatarMark Brown <broonie@kernel.org>
parent f5a4d7f5
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -1161,6 +1161,7 @@ static int tegra_qspi_combined_seq_xfer(struct tegra_qspi *tqspi,
	u32 address_value = 0;
	u32 cmd_config = 0, addr_config = 0;
	u8 cmd_value = 0, val = 0;
	unsigned long flags;

	/* Enable Combined sequence mode */
	val = tegra_qspi_readl(tqspi, QSPI_GLOBAL_CONFIG);
@@ -1264,13 +1265,17 @@ static int tegra_qspi_combined_seq_xfer(struct tegra_qspi *tqspi,
			tegra_qspi_transfer_end(spi);
			spi_transfer_delay_exec(xfer);
		}
		spin_lock_irqsave(&tqspi->lock, flags);
		tqspi->curr_xfer = NULL;
		spin_unlock_irqrestore(&tqspi->lock, flags);
		transfer_phase++;
	}
	ret = 0;

exit:
	spin_lock_irqsave(&tqspi->lock, flags);
	tqspi->curr_xfer = NULL;
	spin_unlock_irqrestore(&tqspi->lock, flags);
	msg->status = ret;

	return ret;