Skip to content

Commit 5acee4a

Browse files
decsnykartben
authored andcommitted
spi_nxp_lpspi: Prevent edge case causing DMA error
Stop the transfer with error if at any point there is some execution reached where transfer is being set up for 0 length, this can cause problems where for example eDMA set up with this nonsense 0 length channels can get an infinite error interrupt. And this is probably an erroneously crafted transfer request anyways. Signed-off-by: Declan Snyder <declan.snyder@nxp.com>
1 parent 2f678bd commit 5acee4a

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

drivers/spi/spi_nxp_lpspi/spi_nxp_lpspi_dma.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,14 @@ static inline int spi_mcux_dma_rxtx_load(const struct device *dev)
102102
size_t next_chunk_size = spi_context_max_continuous_chunk(ctx);
103103
int ret = 0;
104104

105+
if (next_chunk_size == 0) {
106+
/* In case both buffers are 0 length, we should not even be here
107+
* and attempting to set up a DMA transfer like this will cause
108+
* errors that lock up the system in some cases with eDMA.
109+
*/
110+
return -ENODATA;
111+
}
112+
105113
ret = spi_mcux_dma_tx_load(dev, ctx->tx_buf, next_chunk_size);
106114
if (ret != 0) {
107115
return ret;
@@ -223,7 +231,11 @@ static int transceive_dma(const struct device *dev, const struct spi_config *spi
223231
spi_context_cs_control(ctx, true);
224232

225233
ret = spi_mcux_dma_next_fill(dev);
226-
if (ret) {
234+
if (ret == -ENODATA) {
235+
/* No transfer to do? So just exit */
236+
ret = 0;
237+
goto out;
238+
} else if (ret) {
227239
goto out;
228240
}
229241

0 commit comments

Comments
 (0)