From c512e04232247716823a52909bd6f1c652812d39 Mon Sep 17 00:00:00 2001 From: Guennadi Liakhovetski Date: Fri, 8 Oct 2021 16:02:17 +0200 Subject: [PATCH 1/2] pipeline: check error codes, propagate errors pipeline_for_each_comp() and buffer_set_params() can fail, make sure to check their return values and propagate any errors. Signed-off-by: Guennadi Liakhovetski --- src/audio/pipeline/pipeline-params.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/audio/pipeline/pipeline-params.c b/src/audio/pipeline/pipeline-params.c index 86ed235a8c01..44406474a225 100644 --- a/src/audio/pipeline/pipeline-params.c +++ b/src/audio/pipeline/pipeline-params.c @@ -154,14 +154,18 @@ static int pipeline_comp_hw_params(struct comp_dev *current, pipe_dbg(current->pipeline, "pipeline_comp_hw_params(), current->comp.id = %u, dir = %u", dev_comp_id(current), dir); - pipeline_for_each_comp(current, ctx, dir); + ret = pipeline_for_each_comp(current, ctx, dir); + if (ret < 0) + return ret; /* Fetch hardware stream parameters from DAI component */ if (dev_comp_type(current) == SOF_COMP_DAI) { ret = comp_dai_get_hw_params(current, &ppl_data->params->params, dir); if (ret < 0) { - pipe_err(current->pipeline, "pipeline_find_dai_comp(): comp_dai_get_hw_params() error."); + pipe_err(current->pipeline, + "pipeline_comp_hw_params(): failed getting DAI parameters: %d", + ret); return ret; } } @@ -169,12 +173,15 @@ static int pipeline_comp_hw_params(struct comp_dev *current, /* set buffer parameters */ if (calling_buf) { buffer_lock(calling_buf, &flags); - buffer_set_params(calling_buf, &ppl_data->params->params, - BUFFER_UPDATE_IF_UNSET); + ret = buffer_set_params(calling_buf, &ppl_data->params->params, + BUFFER_UPDATE_IF_UNSET); buffer_unlock(calling_buf, flags); + if (ret < 0) + pipe_err(current->pipeline, + "pipeline_comp_hw_params(): buffer_set_params(): %d", ret); } - return 0; + return ret; } /* Send pipeline component params from host to endpoints. From 9eab81ddc6d50ed27891c7c49b9b97d82d9fe723 Mon Sep 17 00:00:00 2001 From: Guennadi Liakhovetski Date: Fri, 8 Oct 2021 17:09:18 +0200 Subject: [PATCH 2/2] pipeline: stop recursing if requested by a component When recursing pipeline components, using pipeline_for_each_comp(), each component's .comp_func() method is called. Those methods can return 0 for success, a negative error code or PPL_STATUS_PATH_STOP if recursing should stop. However, the latter code is ignored by pipeline_for_each_comp(). Add a check for that code and terminate recursion if detected. Signed-off-by: Guennadi Liakhovetski --- src/audio/pipeline/pipeline-graph.c | 2 +- src/audio/pipeline/pipeline-stream.c | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/audio/pipeline/pipeline-graph.c b/src/audio/pipeline/pipeline-graph.c index d013fd2a59fd..dbb560ade044 100644 --- a/src/audio/pipeline/pipeline-graph.c +++ b/src/audio/pipeline/pipeline-graph.c @@ -392,7 +392,7 @@ int pipeline_for_each_comp(struct comp_dev *current, buffer_lock(buffer, &flags); buffer->walking = false; buffer_unlock(buffer, flags); - if (err < 0) + if (err < 0 || err == PPL_STATUS_PATH_STOP) return err; } } diff --git a/src/audio/pipeline/pipeline-stream.c b/src/audio/pipeline/pipeline-stream.c index 974fb0578a19..23ddfd112295 100644 --- a/src/audio/pipeline/pipeline-stream.c +++ b/src/audio/pipeline/pipeline-stream.c @@ -383,7 +383,7 @@ int pipeline_trigger_run(struct pipeline *p, struct comp_dev *host, int cmd) p->trigger.delay = (data.delay_ms * 1000 + p->period - 1) / p->period; p->trigger.cmd = data.cmd; - return ret; + return 0; } list_init(&walk_ctx.pipelines); @@ -396,6 +396,8 @@ int pipeline_trigger_run(struct pipeline *p, struct comp_dev *host, int cmd) if (ret < 0) pipe_err(p, "pipeline_trigger(): ret = %d, host->comp.id = %u, cmd = %d", ret, dev_comp_id(host), cmd); + else if (ret == PPL_STATUS_PATH_STOP) + ret = 0; if (pipeline_is_timer_driven(p)) return ret;