From 81beb31f5e46022f6f68a352ef92124f6adc9c3a Mon Sep 17 00:00:00 2001 From: Kai Vehmanen Date: Thu, 7 Aug 2025 18:25:19 +0300 Subject: [PATCH] ASoC: SOF: ipc4-pcm: do not report invalid delay values Add a sanity check for the calculated delay value before reporting it to the application. If the value is clearly invalid, emit a rate limited warning to kernel log and return a zero delay. This can occur e.g if the host or link DMA hits a buffer over/underrun condition. Signed-off-by: Kai Vehmanen --- sound/soc/sof/ipc4-pcm.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/sound/soc/sof/ipc4-pcm.c b/sound/soc/sof/ipc4-pcm.c index 9d29d2e56c0086..8f213a68f7503b 100644 --- a/sound/soc/sof/ipc4-pcm.c +++ b/sound/soc/sof/ipc4-pcm.c @@ -59,6 +59,8 @@ struct sof_ipc4_pcm_stream_priv { */ #define DELAY_BOUNDARY U32_MAX +#define DELAY_MAX (DELAY_BOUNDARY >> 1) + static inline struct sof_ipc4_timestamp_info * sof_ipc4_sps_to_time_info(struct snd_sof_pcm_stream *sps) { @@ -1266,6 +1268,12 @@ static int sof_ipc4_pcm_pointer(struct snd_soc_component *component, else time_info->delay = head_cnt - tail_cnt; + if (time_info->delay > DELAY_MAX) { + dev_dbg_ratelimited(sdev->dev, + "inaccurate delay, host %llu dai_cnt %llu", host_cnt, dai_cnt); + time_info->delay = 0; + } + /* * Convert the host byte counter to PCM pointer which wraps in buffer * and it is in frames