From: Liyin Zhang <[email protected]>

When the data length to be written exceeds 256 bytes, the
spi-zynqmp-gqspi driver issues GENFIFO entries using a combination of
exponent and immediate modes, with the immediate transfers aligned to
4 bytes. Accordingly, when filling the TX FIFO, the data is also
padded to achieve 4-byte alignment.
However, when filling the last incomplete 4-byte chunk of xqspi->txbuf,
the local variable intermediate is not initialized, causing the padding
bytes to contain random values.
Initialize intermediate to 0xFFFFFFFF to avoid this issue.
In addition, after the final memcpy, count should be assigned first
before clearing xqspi->bytes_to_transfer.

Signed-off-by: Liyin Zhang <[email protected]>
---
 drivers/spi/spi-zynqmp-gqspi.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/spi/spi-zynqmp-gqspi.c b/drivers/spi/spi-zynqmp-gqspi.c
index cd4f226d557f..877880ef7561 100644
--- a/drivers/spi/spi-zynqmp-gqspi.c
+++ b/drivers/spi/spi-zynqmp-gqspi.c
@@ -687,11 +687,12 @@ static void zynqmp_qspi_filltxfifo(struct zynqmp_qspi 
*xqspi, int size)
                        xqspi->bytes_to_transfer -= 4;
                        count += 4;
                } else {
+                       intermediate = 0xFFFFFFFF;
                        memcpy(&intermediate, xqspi->txbuf,
                               xqspi->bytes_to_transfer);
                        xqspi->txbuf += xqspi->bytes_to_transfer;
-                       xqspi->bytes_to_transfer = 0;
                        count += xqspi->bytes_to_transfer;
+                       xqspi->bytes_to_transfer = 0;
                }
                zynqmp_gqspi_write(xqspi, GQSPI_TXD_OFST, intermediate);
        }
-- 
2.34.1

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#15927): 
https://lists.yoctoproject.org/g/linux-yocto/message/15927
Mute This Topic: https://lists.yoctoproject.org/mt/116215880/21656
Group Owner: [email protected]
Unsubscribe: https://lists.yoctoproject.org/g/linux-yocto/unsub 
[[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

Reply via email to