SPI queue overflow prevention
Posted: Mon Jul 14, 2025 6:40 pm
Hello,
I have determined first hand that the SPI driver does not have any code to prevent an overflow of the receiving transaction queue when using spi_device_queue_trans/spi_device_get_trans_result. If the application keeps filling the tx queue the driver task will keep transmitting the transactions even when the rx is full. This will lead to memory leaks if the code uses allocated memory that needs to be freed after the transaction has completed.
Line 970 spi_master.c
if (!(host->device[cs]->cfg.flags & SPI_DEVICE_NO_RETURN_RESULT)) {
//Return transaction descriptor.
xQueueSendFromISR(host->device[cs]->ret_queue, &host->cur_trans_buf, &do_yield);
}
This does not check to confirm the transaction was added to the queue. Further down in the TX section of the task it does not appear to check to see if ret_queue has space before polling from the trans_queue (roughly line 1008). Should this not be at least an option to have the driver confirm there is adequate space in the ret_queue before starting a transmission?
Thanks,
Scott L
I have determined first hand that the SPI driver does not have any code to prevent an overflow of the receiving transaction queue when using spi_device_queue_trans/spi_device_get_trans_result. If the application keeps filling the tx queue the driver task will keep transmitting the transactions even when the rx is full. This will lead to memory leaks if the code uses allocated memory that needs to be freed after the transaction has completed.
Line 970 spi_master.c
if (!(host->device[cs]->cfg.flags & SPI_DEVICE_NO_RETURN_RESULT)) {
//Return transaction descriptor.
xQueueSendFromISR(host->device[cs]->ret_queue, &host->cur_trans_buf, &do_yield);
}
This does not check to confirm the transaction was added to the queue. Further down in the TX section of the task it does not appear to check to see if ret_queue has space before polling from the trans_queue (roughly line 1008). Should this not be at least an option to have the driver confirm there is adequate space in the ret_queue before starting a transmission?
Thanks,
Scott L