-
Notifications
You must be signed in to change notification settings - Fork 361
sink: guard against zero frame size in free-frames #10937
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -109,7 +109,15 @@ EXPORT_SYMBOL(sink_get_frame_bytes); | |
|
|
||
| size_t sink_get_free_frames(struct sof_sink *sink) | ||
| { | ||
| return sink_get_free_size(sink) / sink_get_frame_bytes(sink); | ||
| size_t frame_bytes = sink_get_frame_bytes(sink); | ||
|
|
||
| /* frame_bytes is channels * sample_size and both are host-influenced; | ||
| * guard against a zero divisor (e.g. channels == 0) | ||
| */ | ||
| if (!frame_bytes) | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should reject a frame size of 0 bytes before we get to this call, is there a check higher in the stack that validates this ?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I checked — there isn't a central one. |
||
| return 0; | ||
|
|
||
| return sink_get_free_size(sink) / frame_bytes; | ||
| } | ||
| EXPORT_SYMBOL(sink_get_free_frames); | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a hot-path call. Should such checks be made at prepare() stage and not on the hot path?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed in principle. Two notes: the guard reuses the
frame_bytesvalue that's already computed one line above and adds a single (well-predicted) branch, so the hot-path cost is essentially nil — the division it protects is the expensive part. But the root cause is channels_count == 0 from base_cfg reaching the audio_stream, and per my reply to Liam there's no central reject for that today. Options: (a) keep this defensive guard, or (b) reject channels_count == 0 once at module/base_cfg validation (a new central check) and drop this. (b) is the cleaner long-term fix but a broader core change. Happy to do (b) if you'd prefer — which way do you want it?