Skip to content

Commit 921da68

Browse files
committed
sink: guard against zero frame size in free-frames
Free-frames divided the free size by the frame size, which is channels times sample size and can be zero when the channel count is zero. Return zero instead of dividing by zero. Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
1 parent 3f7738d commit 921da68

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

src/module/audio/sink_api.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,15 @@ EXPORT_SYMBOL(sink_get_frame_bytes);
109109

110110
size_t sink_get_free_frames(struct sof_sink *sink)
111111
{
112-
return sink_get_free_size(sink) / sink_get_frame_bytes(sink);
112+
size_t frame_bytes = sink_get_frame_bytes(sink);
113+
114+
/* frame_bytes is channels * sample_size and both are host-influenced;
115+
* guard against a zero divisor (e.g. channels == 0)
116+
*/
117+
if (!frame_bytes)
118+
return 0;
119+
120+
return sink_get_free_size(sink) / frame_bytes;
113121
}
114122
EXPORT_SYMBOL(sink_get_free_frames);
115123

0 commit comments

Comments
 (0)