From 921da687333901be532409b51cb66f5920872add Mon Sep 17 00:00:00 2001 From: Liam Girdwood Date: Thu, 11 Jun 2026 14:31:24 +0100 Subject: [PATCH] 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 --- src/module/audio/sink_api.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/module/audio/sink_api.c b/src/module/audio/sink_api.c index c0a94031f105..fb576adc40e7 100644 --- a/src/module/audio/sink_api.c +++ b/src/module/audio/sink_api.c @@ -109,7 +109,15 @@ EXPORT_SYMBOL(sink_get_frame_bytes); size_t sink_get_free_frames(struct sof_sink *sink) { - return sink_get_free_size(sink) / sink_get_frame_bytes(sink); + size_t frame_bytes = sink_get_frame_bytes(sink); + + /* frame_bytes is channels * sample_size and both are host-influenced; + * guard against a zero divisor (e.g. channels == 0) + */ + if (!frame_bytes) + return 0; + + return sink_get_free_size(sink) / frame_bytes; } EXPORT_SYMBOL(sink_get_free_frames);