Skip to content
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

smart_amp_test: fix crash due to different source formats #9020

Merged
merged 1 commit into from
Apr 16, 2024

Conversation

tobonex
Copy link
Contributor

@tobonex tobonex commented Apr 10, 2024

This patch fixes a rare crash while testing multiple-pause-resume.sh described in #8651

Explanation:
Dai copier sends data to smart_amp in lnl nocodec. Smart_amp_test uses a process function to just copy buffer contents from sources to sink. The bind between those two uses a 16bit format buffer, while other smart amp pins use 32bit. Smart_amp_test in .prepare function chooses a process callback based only on the format of the sink. This way a 32bit process function is chosen, despite one of the sources being 16bit which risks misalignment. Crash is pretty rare because the misalignment only happens when dai_copier outputs one sample less (an odd number), probably due to stress.

Pushing one of the possible fixes here, but there are other options I can write and push if you want:
- Choose 32bit only when all the sinks and sources are 32bit, else use 16bit process (I pushed this one)
- Create a new process function that always copies word by word, and copies the misaligned data that remains byte by byte. Remove the other process functions.
- Ignore the optimization and just always use process_s16 to be safe

Smart amp test chooses a process function based on the sink only. Because
of this, there's a possibility that one of the sources has a 16bit format,
which can't be safely processed by the 32bit process function. The crash
only happened when dai_copier sent one less sample than usual to the
smart_amp. This makes total sample count an odd number, making the data in
the audio_stream buffer misaligned.

This patch changes the prepare function of smart_amp_test to consider all
the sources and sinks while deciding which process function to use.

Signed-off-by: Tobiasz Dryjanski <tobiaszx.dryjanski@intel.com>
@tobonex tobonex marked this pull request as ready for review April 11, 2024 07:43
@lgirdwood lgirdwood merged commit 821f961 into thesofproject:main Apr 16, 2024
44 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.

4 participants