From c417ce6746fc5504192132ba9aa3c9f0cb087194 Mon Sep 17 00:00:00 2001 From: Gwenhael Goavec-Merou Date: Wed, 6 Sep 2023 15:50:28 +0200 Subject: [PATCH] lattice: spi_put: avoid loop when tx == NULL --- src/lattice.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/lattice.cpp b/src/lattice.cpp index 6095961d11..ac7f7932e8 100644 --- a/src/lattice.cpp +++ b/src/lattice.cpp @@ -1361,10 +1361,13 @@ int Lattice::spi_put(const uint8_t *tx, uint8_t *rx, uint32_t len) uint8_t jtx[len]; uint8_t jrx[len]; - for (uint32_t i = 0; i < len; ++i) { - jtx[i] = (tx) ? LatticeBitParser::reverseByte(tx[i]) : 0; - jrx[i] = 0; - } + memset(jrx, 0, len); + + if (tx) + for (uint32_t i = 0; i < len; ++i) + jtx[i] = LatticeBitParser::reverseByte(tx[i]); + else + memset(jtx, 0, len); /* send first already stored cmd, * in the same time store each byte