Skip to content

Commit f6a9a1f

Browse files
decsnynashif
authored andcommitted
spi_nxp_lpspi: Fix unit of buf_len in fill_tx_fifo
The buf_len parameter of lpspi_fill_tx_fifo is supposed to be bytes, so we do not need to convert it. This could cause an issue if the end of the buffer is less bytes than the word size. Signed-off-by: Declan Snyder <declan.snyder@nxp.com>
1 parent e9d964f commit f6a9a1f

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

drivers/spi/spi_nxp_lpspi/spi_nxp_lpspi.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,17 +112,16 @@ static inline void lpspi_fill_tx_fifo(const struct device *dev, const uint8_t *b
112112
struct lpspi_data *data = dev->data;
113113
struct lpspi_driver_data *lpspi_data = (struct lpspi_driver_data *)data->driver_data;
114114
uint8_t word_size = lpspi_data->word_size_bytes;
115-
size_t buf_remaining_bytes = buf_len * word_size;
116115
size_t offset = 0;
117116
uint32_t next_word;
118117
uint32_t next_word_bytes;
119118

120119
for (int word_count = 0; word_count < fill_len; word_count++) {
121-
next_word_bytes = MIN(word_size, buf_remaining_bytes);
120+
next_word_bytes = MIN(word_size, buf_len);
122121
next_word = lpspi_next_tx_word(dev, buf, offset, next_word_bytes);
123122
base->TDR = next_word;
124123
offset += word_size;
125-
buf_remaining_bytes -= word_size;
124+
buf_len -= word_size;
126125
}
127126

128127
LOG_DBG("Filled TX FIFO to %d words (%d bytes)", fill_len, offset);

0 commit comments

Comments
 (0)