From 908b9d0511008e440be59cba462daa9c0d1884ae Mon Sep 17 00:00:00 2001 From: Tomasz Lauda Date: Fri, 13 Mar 2020 10:54:09 +0100 Subject: [PATCH] mux: add missing buffer locks Adds missing buffer locks to mux_copy function. demux_copy has already had them before. Signed-off-by: Tomasz Lauda --- src/audio/mux/mux.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/audio/mux/mux.c b/src/audio/mux/mux.c index 328d288400dd..e5e55d60656b 100644 --- a/src/audio/mux/mux.c +++ b/src/audio/mux/mux.c @@ -387,6 +387,7 @@ static int mux_copy(struct comp_dev *dev) uint32_t frames = -1; uint32_t sources_bytes[MUX_MAX_STREAMS] = { 0 }; uint32_t sink_bytes; + uint32_t flags = 0; comp_dbg(dev, "mux_copy()"); @@ -399,11 +400,14 @@ static int mux_copy(struct comp_dev *dev) /* align source streams with their respective configurations */ list_for_item(clist, &dev->bsource_list) { source = container_of(clist, struct comp_buffer, sink_list); + buffer_lock(source, &flags); if (source->source->state == dev->state) { num_sources++; i = get_stream_index(cd, source->pipeline_id); sources[i] = source; sources_stream[i] = &source->stream; + } else { + buffer_unlock(source, flags); } } @@ -414,9 +418,19 @@ static int mux_copy(struct comp_dev *dev) sink = list_first_item(&dev->bsink_list, struct comp_buffer, source_list); + buffer_lock(sink, &flags); + /* check if sink is active */ - if (sink->sink->state != dev->state) + if (sink->sink->state != dev->state) { + for (i = 0; i < MUX_MAX_STREAMS; i++) { + if (!sources[i]) + continue; + buffer_unlock(sources[i], flags); + } + + buffer_unlock(sink, flags); return 0; + } for (i = 0; i < MUX_MAX_STREAMS; i++) { if (!sources[i]) @@ -424,8 +438,11 @@ static int mux_copy(struct comp_dev *dev) frames = MIN(frames, audio_stream_avail_frames(sources_stream[i], &sink->stream)); + buffer_unlock(sources[i], flags); } + buffer_unlock(sink, flags); + for (i = 0; i < MUX_MAX_STREAMS; i++) { if (!sources[i]) continue;