From: Lee Jones <lee@kernel.org>
To: lee@kernel.org, Mark Brown <broonie@kernel.org>,
Tomoya MORINAGA <tomoya.rohm@gmail.com>,
Grant Likely <grant.likely@secretlab.ca>,
linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: stable@vger.kernel.org
Subject: [PATCH 05/10] spi: topcliff-pch: Advance tx_buf between DMA chunks
Date: Thu, 19 Nov 2026 09:17:17 +0000 [thread overview]
Message-ID: <20261119091810.3440619-6-lee@kernel.org> (raw)
In-Reply-To: <20261119091810.3440619-1-lee@kernel.org>
In DMA mode, pch_spi_process_messages() splits transfers larger than
PCH_BUF_SIZE into chunks and calls pch_spi_handle_dma() once per chunk.
pch_spi_handle_dma() copies the TX data through a local pointer and
never stores the advanced position back into the transfer, so every
chunk after the first retransmits the data from the first chunk.
The RX side already writes its advanced pointer back and restores the
original rx_buf once the transfer is complete.
Do the same for tx_buf, so that each chunk sends the correct slice of
the buffer, and restore the original tx_buf once the transfer has
completed or failed.
Advancing tx_buf by the number of bytes copied relies on the following
commit, which ensures that each chunk covers no more than the bytes
accounted for by the loop in pch_spi_process_messages():
commit 3515e312e096 ("spi: topcliff-pch: clamp DMA bpw_len by bytes not words")
Fixes: 7d05b3e868ee ("spi-topcliff-pch: Fix issue for transmitting over 4KByte")
Closes: https://sashiko.dev/#/bug/linux-625e2f07-fb68-446b-b1a8-b1f66aacb62e
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
drivers/spi/spi-topcliff-pch.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/drivers/spi/spi-topcliff-pch.c b/drivers/spi/spi-topcliff-pch.c
index 0bec3012a6bc..cbe76c4ae2e8 100644
--- a/drivers/spi/spi-topcliff-pch.c
+++ b/drivers/spi/spi-topcliff-pch.c
@@ -947,11 +947,13 @@ static void pch_spi_handle_dma(struct pch_spi_data *data, int *bpw)
tx_dma_buf = dma->tx_buf_virt;
for (i = 0; i < data->bpw_len; i++)
*tx_dma_buf++ = *tx_buf++;
+ data->cur_trans->tx_buf = tx_buf;
} else {
tx_sbuf = data->cur_trans->tx_buf;
tx_dma_sbuf = dma->tx_buf_virt;
for (i = 0; i < data->bpw_len; i++)
*tx_dma_sbuf++ = *tx_sbuf++;
+ data->cur_trans->tx_buf = tx_sbuf;
}
}
@@ -1180,10 +1182,12 @@ static void pch_spi_process_messages(struct work_struct *pwork)
if (data->use_dma) {
int i;
char *save_rx_buf = data->cur_trans->rx_buf;
+ const void *save_tx_buf = data->cur_trans->tx_buf;
for (i = 0; i < cnt; i++) {
pch_spi_handle_dma(data, &bpw);
if (!pch_spi_start_transfer(data)) {
+ data->cur_trans->tx_buf = save_tx_buf;
data->transfer_complete = true;
data->current_msg->status = -EIO;
data->current_msg->complete
@@ -1196,6 +1200,7 @@ static void pch_spi_process_messages(struct work_struct *pwork)
pch_spi_copy_rx_data_for_dma(data, bpw);
}
data->cur_trans->rx_buf = save_rx_buf;
+ data->cur_trans->tx_buf = save_tx_buf;
} else {
pch_spi_set_tx(data, &bpw);
pch_spi_set_ir(data);
--
2.56.1.708.g77570a6a1d-goog
next prev parent reply other threads:[~2026-11-19 9:18 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-19 9:17 [PATCH 00/10] spi: Fix data corruption, uninitialised data leaks and bounds checks Lee Jones
2026-11-19 9:17 ` [PATCH 01/10] spi: fsl-cpm: Map the zero page's address, not its struct page Lee Jones
2026-11-19 9:17 ` [PATCH 02/10] spi: bcm2835: Store native chip-select GPIO descriptor per device Lee Jones
2026-11-19 9:17 ` [PATCH 03/10] spi: ch341: Limit transfers to the hardware packet size Lee Jones
2026-11-19 9:17 ` [PATCH 04/10] spi: sprd-adi: Do not copy uninitialised data to rx_buf on read failure Lee Jones
2026-11-19 9:17 ` Lee Jones [this message]
2026-11-19 9:17 ` [PATCH 06/10] spi: cadence-quadspi: Bound chip select against f_pdata array size Lee Jones
2026-11-19 9:17 ` [PATCH 07/10] spi: cadence-xspi: Zero the tail word in m_iowriteq() Lee Jones
2026-11-19 9:17 ` [PATCH 08/10] spi: fsl-qspi: Propagate clock errors from fsl_qspi_select_mem() Lee Jones
2026-11-19 9:17 ` [PATCH 09/10] spi: cadence-xspi: Advance tx pointer between Marvell b0 chunks Lee Jones
2026-11-19 9:17 ` [PATCH 10/10] spi: cadence-xspi: Skip tail read for qword-aligned Marvell b0 receives Lee Jones
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261119091810.3440619-6-lee@kernel.org \
--to=lee@kernel.org \
--cc=broonie@kernel.org \
--cc=grant.likely@secretlab.ca \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-spi@vger.kernel.org \
--cc=stable@vger.kernel.org \
--cc=tomoya.rohm@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox