ASoC: SOF: ipc4: avoid uninitialized default instance 0
authorRanjani Sridharan <ranjani.sridharan@linux.intel.com>
Mon, 7 Aug 2023 21:09:42 +0000 (16:09 -0500)
committerMark Brown <broonie@kernel.org>
Mon, 7 Aug 2023 22:09:32 +0000 (23:09 +0100)
When a pipeline contains multiple DAI widgets, the pipe_widget is not
set up except for the first DAI. This result in the pipe_widget having
a default instance 0, which can conflict with another real the
pipeline instance 0 and leads to spurious transitions.

This patch makes sure the instance_id is properly initialized to a
-EINVAL value.

Signed-off-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Reviewed-by: Bard Liao <yung-chuan.liao@linux.intel.com>
Link: https://lore.kernel.org/r/20230807210959.506849-4-pierre-louis.bossart@linux.intel.com
Signed-off-by: Mark Brown <broonie@kernel.org>
sound/soc/sof/intel/hda-dai-ops.c
sound/soc/sof/ipc4-topology.c
sound/soc/sof/topology.c

index f351379..e9ae389 100644 (file)
@@ -234,6 +234,9 @@ static int hda_ipc4_pre_trigger(struct snd_sof_dev *sdev, struct snd_soc_dai *cp
        pipe_widget = swidget->spipe->pipe_widget;
        pipeline = pipe_widget->private;
 
+       if (pipe_widget->instance_id < 0)
+               return 0;
+
        mutex_lock(&ipc4_data->pipeline_state_mutex);
 
        switch (cmd) {
@@ -297,6 +300,9 @@ static int hda_ipc4_post_trigger(struct snd_sof_dev *sdev, struct snd_soc_dai *c
        pipe_widget = swidget->spipe->pipe_widget;
        pipeline = pipe_widget->private;
 
+       if (pipe_widget->instance_id < 0)
+               return 0;
+
        mutex_lock(&ipc4_data->pipeline_state_mutex);
 
        switch (cmd) {
index a4e1a70..9bc94be 100644 (file)
@@ -2319,6 +2319,7 @@ static int sof_ipc4_widget_free(struct snd_sof_dev *sdev, struct snd_sof_widget
                pipeline->mem_usage = 0;
                pipeline->state = SOF_IPC4_PIPE_UNINITIALIZED;
                ida_free(&pipeline_ida, swidget->instance_id);
+               swidget->instance_id = -EINVAL;
        } else {
                struct snd_sof_widget *pipe_widget = swidget->spipe->pipe_widget;
                struct sof_ipc4_pipeline *pipeline = pipe_widget->private;
index 698129d..1afcbb1 100644 (file)
@@ -2157,6 +2157,8 @@ static int sof_complete(struct snd_soc_component *scomp)
                struct snd_sof_widget *pipe_widget = spipe->pipe_widget;
                struct snd_sof_widget *swidget;
 
+               pipe_widget->instance_id = -EINVAL;
+
                /* Update the scheduler widget's IPC structure */
                if (widget_ops && widget_ops[pipe_widget->id].ipc_setup) {
                        ret = widget_ops[pipe_widget->id].ipc_setup(pipe_widget);