platform: stm32: fix SPI DMA timeout underflow#3116
Conversation
This fixes an issue where an integer underflow in the timeout loop masks DMA failures and creates a race condition that reports false timeouts. Resolves analogdevicesinc#3115 Signed-off-by: Max Orlemann <maxorlemann@gmail.com>
|
Thanks for catching it and submitting the fix. While you are at it, and because they seem identical, could you fix the same issue in xspi implementation ? You can put the xspi change in the same commit as they are tightly related. |
| if (timeout == 0) | ||
| /* Fix: Check the actual completion flag instead of the counter */ | ||
| if (!sdesc->stm32_spi_dma_done) { | ||
| /* Optional: Add HAL_DMA_Abort_IT() or similar cleanup here */ |
There was a problem hiding this comment.
i reverted to the original comment /* need some cleanup here? */, as a cleanup still should be implemented similar to the xspi implementation. here it is more complex, because of seperate handles for rx and txdma_ch
There was a problem hiding this comment.
You are right, just squash the commits for now into a single commit and leave the original question there. We can deal with that separately in another PR and merge this one.
Remove comments fix same issues in stm32_xspi.c
This fixes an issue where an integer underflow in the timeout loop masks DMA failures and creates a race condition that reports false timeouts.
Resolves #3115
Pull Request Description
Problem
The loop
while (timeout--)instm32_spi_transfer_dma()causes two issues:timeoutdecrements past 0 to0xFFFFFFFF. The finalif (timeout == 0)check fails, and the function incorrectly returns0(Success).timeoutis already0, causing a false-ETIMEreturn.Solution
while (timeout > 0)to prevent underflow.!sdesc->stm32_spi_dma_doneinstead of the counter.Testing
Verified via hardware debugging on STM32 with an ADIN1110 by simulating a DMA stall. The driver now correctly catches the stall and returns
-ETIME.PR Type
PR Checklist