Audio: Volume: Fix a possible overflow in S24_LE format volume#10181
Merged
lgirdwood merged 1 commit intothesofproject:mainfrom Aug 26, 2025
Merged
Audio: Volume: Fix a possible overflow in S24_LE format volume#10181lgirdwood merged 1 commit intothesofproject:mainfrom
lgirdwood merged 1 commit intothesofproject:mainfrom
Conversation
The AE_SRAI32R() right shift with round could cause the value to go over S24_LE range by one if the gain would be over one or 0 dB (only possible in IPC3). The rounding shift is unnecessary because the gain product is already rounded in the multiply instruction. The SRAI32() instruction does just the shift. Fixes: f3e3403 ("Audio: Volume: Add IPC4 native Q1.31 mode and optimize") Signed-off-by: Seppo Ingalsuo <seppo.ingalsuo@linux.intel.com>
Collaborator
Author
|
I noticed this overflow risk when working with Level Multiplier. The HiFi5 version has the non-rounding shift, so it didn't need the fix. |
There was a problem hiding this comment.
Pull Request Overview
Fixes a potential overflow bug in S24_LE format volume processing where rounding during right shift could cause values to exceed the valid range when gain is over 0 dB.
- Replace
AE_SRAI32R()(shift-right with rounding) withAE_SRAI32()(plain shift-right) to prevent overflow - Update comments to reflect the removal of rounding operation
- Apply fix consistently across all HiFi3/HiFi4 volume processing variants
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/audio/volume/volume_hifi4_with_peakvol.c | Remove rounding from S24_LE shift operation to prevent overflow |
| src/audio/volume/volume_hifi4.c | Remove rounding from S24_LE shift operation to prevent overflow |
| src/audio/volume/volume_hifi3_with_peakvol.c | Remove rounding from S24_LE shift operation to prevent overflow |
| src/audio/volume/volume_hifi3.c | Remove rounding from S24_LE shift operation to prevent overflow |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
lgirdwood
approved these changes
Aug 25, 2025
Member
jsarha
approved these changes
Aug 26, 2025
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.
The AE_SRAI32R() right shift with round could cause the value to go over S24_LE range by one if the gain would be over one or 0 dB (only possible in IPC3). The rounding shift is unnecessary because the gain product is already rounded in the multiply instruction. The SRAI32() instruction does just the shift.
Fixes: f3e3403 ("Audio: Volume: Add IPC4 native Q1.31 mode
and optimize")