Skip to content

Conversation

@singalsu
Copy link
Collaborator

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")

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>
@singalsu
Copy link
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.

@singalsu singalsu marked this pull request as ready for review August 22, 2025 09:29
Copilot AI review requested due to automatic review settings August 22, 2025 09:29
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) with AE_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
Copy link
Member

@singalsu alsa-bat passing. @kv2019i @jsarha pls review

@lgirdwood lgirdwood merged commit a3997f0 into thesofproject:main Aug 26, 2025
39 of 45 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants