Skip to content

Commit

Permalink
module: sink: source: Prevent division by zero issue
Browse files Browse the repository at this point in the history
This patch prevents division by zero, when
source_get_frame_bytes() routine returns 0.

This change fixes issue thesofproject#8414.
The problem happens due to race condition during pipeline pause operation.
The exact failure mechanism require additional debug, but checking
frame_bytes value before division prevents exceptions.

Signed-off-by: Jaroslaw Stelter <Jaroslaw.Stelter@intel.com>
  • Loading branch information
jxstelter committed Dec 6, 2023
1 parent 6563320 commit 8f4779e
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/module/audio/source_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ size_t source_get_frame_bytes(struct sof_source *source)

size_t source_get_data_frames_available(struct sof_source *source)
{
return source_get_data_available(source) /
source_get_frame_bytes(source);
uint32_t frame_bytes = source_get_frame_bytes(source);

if (frame_bytes > 0)
return source_get_data_available(source) / frame_bytes;
else
return 0;
}

0 comments on commit 8f4779e

Please sign in to comment.