fix stream write racing#3465
Merged
Merged
Conversation
Signed-off-by: HiFiPhile <admin@hifiphile.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a race condition in stream write operations where the FIFO count could change between the initial check and actual usage after the endpoint is claimed.
Changes:
- Re-reads the FIFO count after claiming the stream when
ep_bufis NULL to ensure the count reflects the current state
Comments suppressed due to low confidence (1)
src/tusb.c:388
- The variable
ff_countis now only used for the initial check on line 389, but this check itself could be subject to the same race condition being fixed. Consider either: (1) removingff_countentirely and callingtu_fifo_count(&s->ff)directly in the verification on line 389, or (2) documenting why the stale initial check is acceptable (the race is benign since thecount > 0check at line 400 handles the case where the FIFO becomes empty after claiming).
const uint16_t ff_count = tu_fifo_count(&s->ff);
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Size Difference ReportBecause TinyUSB code size varies by port and configuration, the metrics below represent the averaged totals across all example builds. Note: If there is no change, only one value is shown. Changes >1% in size
Changes <1% in sizeNo entries. No changes
|
me-no-dev
approved these changes
Jan 16, 2026
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.
Describe the PR
FIFO count may change after the stream is acquired.
Fix #3463