spi: spi-zynqmp-gqspi: Fix memory corruption when writing odd-length data in dual parallel mode

In dual parallel mode, the driver was corrupting memory beyond the intended
data length when handling odd length writes as the write length wasn't
aligned to the word boundary expected by the controller. Update the driver
to round up the odd data length to the next word boundary and pad the
additional bytes with 0xFF to prevent memory corruption.

Reported by: Xiangyu Chen <xiangyu.chen@windriver.com>

Signed-off-by: Amit Kumar Mahapatra <amit.kumar-mahapatra@amd.com>
Message-ID: <20250408124331.177119-1-amit.kumar-mahapatra@amd.com>
[ Backport from linux-xlnx branch xilinx-v2025.1
656eee6f4f ]
Signed-off-by: Xiangyu Chen <xiangyu.chen@windriver.com>
Signed-off-by: Bruce Ashfield <bruce.ashfield@gmail.com>
This commit is contained in:
Amit Kumar Mahapatra 2025-06-25 09:29:19 +08:00 committed by Bruce Ashfield
parent 6e66bd3924
commit 5b1fe37b5c

View File

@ -1029,6 +1029,14 @@ static int zynqmp_qspi_exec_op(struct spi_mem *mem,
xqspi->rxbuf = NULL;
xqspi->bytes_to_transfer = op->data.nbytes;
xqspi->bytes_to_receive = 0;
if ((genfifoentry & GQSPI_GENFIFO_STRIPE) &&
(xqspi->bytes_to_transfer % 2)) {
u32 data_len = xqspi->bytes_to_transfer;
xqspi->bytes_to_transfer = roundup(xqspi->bytes_to_transfer, 4);
for (; data_len < xqspi->bytes_to_transfer; data_len++)
*(((u8 *)xqspi->txbuf) + data_len) = 0xFF;
}
zynqmp_qspi_write_op(xqspi, op->data.buswidth,
genfifoentry);
zynqmp_gqspi_write(xqspi, GQSPI_CONFIG_OFST,