Repository navigation
Conversation
up_dma_setup() passed the handle from stm32_dmachannel() straight to stm32_dmasetup(). On the H7, stm32_dmachannel() does not wait for a stream: it returns NULL when every stream of the controller is taken. The open() then asserted in stm32_dmasetup(), or with assertions off dereferenced NULL. Return -EBUSY instead. If the RX stream is the one that is missing, release the TX stream that was already taken, and undo up_setup() for a port that is not the console, so a later open() can succeed once a stream is free. Assisted-by: Claude:claude-opus-5-5 Signed-off-by: Max Kriegleder <max.kriegleder@gmail.com>
maxikrie
requested review from
davids5,
jerpelea and
raiden00pl
as code owners
November 18, 2026 17:59
1 task done
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
On STM32H7, opening a serial port with RX or TX DMA crashes the system if its DMA controller has no free stream left.
stm32_dmachannel()on the H7 (DMAMUX) hands out the first free stream of the requested controller and returns NULL when there is none; it does not block as on F4/F7.up_dma_setup()did not check the handle and passed it tostm32_dmasetup(), which asserts (DEBUGASSERT(handle != NULL)) or, without assertions, dereferences NULL.This PR makes
up_dma_setup()return-EBUSYin that case, soopen()fails withEBUSY. On failure it releases a TX stream that was already taken (when only the RX stream is missing) and undoesup_setup()for a non-console port (clock, pins), so a lateropen()works once a stream is free. The H5 driver already returns-EBUSYhere.This is item 3 of #20244, which says it "can land first", independent of the build-time budget proposed there.
Not changed here: the H7 SPI driver also only
DEBUGASSERTs its DMA handles inspi_bus_initialize(). With assertions off it already falls back tospi_exchange_nodma()when a handle is NULL, so it does not crash; with assertions on it panics at boot. Its comment still saysstm32_dmachannel()blocks, which is the F4/F7 behaviour.Impact
STM32H7 U(S)ARTs with
CONFIG_USARTn_RXDMA/CONFIG_UARTn_TXDMA. Only the path where no DMA stream is available changes:open()now returnsEBUSYinstead of crashing. No change when a stream is available. No Kconfig, API or build changes.Testing
NUCLEO-H753ZI, master fc8d354,
nucleo-h753zi:nsh+CONFIG_STM32_USART6,CONFIG_STM32_DMA1,CONFIG_USART6_RXDMA,CONFIG_USART6_TXDMA,CONFIG_DEBUG_ASSERTIONS. For the test,board.hmaps USART6 to DMA1 (DMAMAP_USART6_RX/TX = DMAMAP_DMA12_USART6xX_0), and a test-only NSH appdmahog [n]takes n (default: all) DMA1 streams withstm32_dmachannel()anddmahog freereleases them. Neither is part of this PR.Toolchain: Arm GNU Toolchain 13.3.Rel1.
tools/checkpatch.sh -g HEADpasses.echo hello > /dev/ttyS1(USART6)dmahog(all 8 DMA1 streams), thenecho hello > /dev/ttyS1stm32_dmasetup(), system panicsopen failed: 16(EBUSY), repeatabledmahog free, thenecho hello > /dev/ttyS1dmahog 7(TX gets the last stream, RX fails),echo x > /dev/ttyS1open failed: 16; afterwardsdmahogagain gets all 8 streams (TX stream released), RCC_APB2ENR.USART6EN = 0 (port shut down)Logs
master
PC 0x0800227a is
stm32_dmasetup(), LR inup_dma_setup()(stm32_serial.c:2261), called fromuart_open().this PR