From 358b36b7dd4152554fce5b09d0447ad6073c8868 Mon Sep 17 00:00:00 2001 From: Seppo Ingalsuo Date: Wed, 25 Nov 2026 19:30:41 +0200 Subject: [PATCH] audio: src: skip processing without one source and one sink The SRC process and is_ready_to_process functions use sources[0] and sinks[0] without checking the number of sources and sinks. The sink of the SRC can be unbound while the pipeline of the SRC keeps running, e.g. when the SRC output goes to a module in another pipeline that is stopped while another PCM keeps the SRC pipeline running. The module adapter then sets num_of_sinks to zero but keeps the stale pointer in mod->sinks[0], and the SRC writes to the freed buffer. This was seen as a DSP panic (StoreProhibited) in src_polyphase_stage_cir() when the 16 kHz ECNS PCM was stopped while the 48 kHz ECNS PCM was running on a shared echo reference pipeline. Do not use sources[0] or sinks[0] unless there is exactly one source and one sink. With a source but no sink, drop the available input instead, so that a shared upstream module, e.g. a copier with several sinks, is not stalled by the full input buffer of the SRC. src_is_ready_to_process() reports data to drop as ready for the DP case. Signed-off-by: Seppo Ingalsuo --- src/audio/src/src_common.c | 40 +++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/src/audio/src/src_common.c b/src/audio/src/src_common.c index d2cb5958b1da..92cc805209cc 100644 --- a/src/audio/src/src_common.c +++ b/src/audio/src/src_common.c @@ -652,10 +652,35 @@ int src_allocate_copy_stages(struct processing_module *mod, struct src_param *pr return 0; } +/** + * \brief Drop the input of an SRC that has no sink. + * + * The sink of the SRC can be unbound while the pipeline of the SRC keeps + * running, e.g. when the SRC output goes to another pipeline that is stopped. + * The input is dropped so that a shared upstream module, e.g. a copier with + * several sinks, is not stalled by the full input buffer of the SRC. + * + * \param[in] source Input of the SRC + * \return 0 or a negative error code + */ +static int src_drop_input(struct sof_source *source) +{ + size_t bytes = source_get_data_frames_available(source) * source_get_frame_bytes(source); + + return source_drop_data(source, bytes); +} + bool src_is_ready_to_process(struct processing_module *mod, struct sof_source **sources, int num_of_sources, struct sof_sink **sinks, int num_of_sinks) { + /* Without a sink, process only to drop the input */ + if (num_of_sources == 1 && !num_of_sinks) + return source_get_data_frames_available(sources[0]) > 0; + + if (num_of_sources != 1 || num_of_sinks != 1) + return false; + return sink_get_free_frames(sinks[0]) || source_get_data_frames_available(sources[0]); } @@ -667,7 +692,20 @@ int src_process(struct processing_module *mod, comp_dbg(mod->dev, "entry"); - /* src component needs 1 source and 1 sink */ + /* src component needs 1 source and 1 sink. The sink or source can be + * unbound while the pipeline of the SRC keeps running, e.g. when the + * SRC output goes to another pipeline that is stopped. The stale + * sinks[0] or sources[0] must not be used then. + */ + if (num_of_sources != 1 || num_of_sinks != 1) { + comp_dbg(mod->dev, "%d sources and %d sinks, no processing", + num_of_sources, num_of_sinks); + if (num_of_sources == 1 && !num_of_sinks) + return src_drop_input(sources[0]); + + return 0; + } + if (!src_get_copy_limits(cd, sources[0], sinks[0])) { comp_dbg(mod->dev, "No data to process."); return 0;