drivers/can: Fix close drain, write-only reader lifecycle, and STM32 RX header#18759
Merged
acassis merged 1 commit intoapache:masterfrom Apr 28, 2026
Merged
Conversation
c9537e6 to
e1149b7
Compare
acassis
reviewed
Apr 18, 2026
e1149b7 to
267649d
Compare
198c069 to
c57c35d
Compare
34b3dde to
10a16f8
Compare
acassis
previously approved these changes
Apr 23, 2026
…RX header Always allocate per-file can_reader on open so write-only descriptors get msgalign / ioctl state; free that context on close when it was never linked into cd_readers (fixes leak). Cap each drain loop (20×500 ms) so close() cannot block forever when bxCAN retries without ACK or dev_txempty never clears. Fix stm32can_vputreg debug log to print the written value (correct parameter name). Signed-off-by: Alexey Matveev <tippet@yandex.ru>
10a16f8 to
8e9f124
Compare
xiaoxiang781216
approved these changes
Apr 24, 2026
Contributor
Author
|
@acassis What to do also need for MR? |
acassis
approved these changes
Apr 28, 2026
Contributor
Everything is fine from my side, I was waiting for other to review too, but since nobody show up, I will merge now. |
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
This PR hardens the generic CAN character driver (drivers/can/can.c) and the STM32 bxCAN backend (arch/arm/src/stm32/stm32_can.c) for write-only use, safe shutdown, and consistent RX headers.
Impact
Loopback / full-header compare: Without clearing the RX header, apps that compare the whole header (loopback tests) could see spurious failures; this change makes RX headers deterministic.
close(): Unbounded waits on TX drain could freeze the app on a silent bus or endless retries; timeouts avoid infinite blocking while still calling dev_shutdown afterward.
Write-only open: Previously f_priv could stay NULL, breaking can_write (msgalign) and some ioctls—risk of fault/panic; allocating can_reader_s for every open fixes that.
Testing
Manual testing on stm32f103-minimum with a custom config (CAN loopback / Example CAN / app scenario as applicable).