Skip to content

Commit 9be436d

Browse files
committed
ASoC: SOF: ipc4-topology: reset pipeline mem_usage during unprepare
The mem_usage for a pipeline is updated when the widgets in the pipeline are prepare. So, reset it when a widget in the pipeline is unprepared. The ipc_unprepare for the pipeline widget might be called multiple times when each widget associated with the pipeline is unprepared and it is harmless. Signed-off-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
1 parent 49d1bf6 commit 9be436d

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

sound/soc/sof/ipc4-topology.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1501,6 +1501,14 @@ static int sof_ipc4_init_input_audio_fmt(struct snd_sof_dev *sdev,
15011501
return i;
15021502
}
15031503

1504+
static void sof_ipc4_unprepare_pipeline_module(struct snd_sof_widget *swidget)
1505+
{
1506+
struct sof_ipc4_pipeline *pipeline = swidget->private;
1507+
1508+
/* reset pipeline memory usage */
1509+
pipeline->mem_usage = 0;
1510+
}
1511+
15041512
static void sof_ipc4_unprepare_copier_module(struct snd_sof_widget *swidget)
15051513
{
15061514
struct sof_ipc4_copier *ipc4_copier = NULL;
@@ -3011,7 +3019,6 @@ static int sof_ipc4_widget_free(struct snd_sof_dev *sdev, struct snd_sof_widget
30113019
dev_err(sdev->dev, "failed to free pipeline widget %s\n",
30123020
swidget->widget->name);
30133021

3014-
pipeline->mem_usage = 0;
30153022
pipeline->state = SOF_IPC4_PIPE_UNINITIALIZED;
30163023
ida_free(&pipeline_ida, swidget->instance_id);
30173024
swidget->instance_id = -EINVAL;
@@ -3637,7 +3644,7 @@ static const struct sof_ipc_tplg_widget_ops tplg_ipc4_widget_ops[SND_SOC_DAPM_TY
36373644
[snd_soc_dapm_scheduler] = {sof_ipc4_widget_setup_comp_pipeline,
36383645
sof_ipc4_widget_free_comp_pipeline,
36393646
pipeline_token_list, ARRAY_SIZE(pipeline_token_list), NULL,
3640-
NULL, NULL},
3647+
NULL, sof_ipc4_unprepare_pipeline_module},
36413648
[snd_soc_dapm_pga] = {sof_ipc4_widget_setup_comp_pga, sof_ipc4_widget_free_comp_pga,
36423649
pga_token_list, ARRAY_SIZE(pga_token_list), NULL,
36433650
sof_ipc4_prepare_gain_module,

sound/soc/sof/sof-audio.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -447,10 +447,16 @@ sof_unprepare_widgets_in_path(struct snd_sof_dev *sdev, struct snd_soc_dapm_widg
447447
goto sink_unprepare;
448448

449449
widget_ops = tplg_ops ? tplg_ops->widget : NULL;
450-
if (widget_ops && widget_ops[widget->id].ipc_unprepare)
450+
if (widget_ops && widget_ops[widget->id].ipc_unprepare) {
451+
struct snd_sof_widget *pipe_widget = swidget->spipe->pipe_widget;
452+
451453
/* unprepare the source widget */
452454
widget_ops[widget->id].ipc_unprepare(swidget);
453455

456+
/* unprepare the widget's pipeline widget */
457+
widget_ops[pipe_widget->id].ipc_unprepare(pipe_widget);
458+
}
459+
454460
swidget->prepared = false;
455461

456462
sink_unprepare:
@@ -1085,10 +1091,16 @@ void snd_sof_unprepare_widgets_in_pipeline(struct snd_soc_dapm_widget *w,
10851091
goto unprepare;
10861092

10871093
widget_ops = tplg_ops ? tplg_ops->widget : NULL;
1088-
if (widget_ops && widget_ops[w->id].ipc_unprepare)
1094+
if (widget_ops && widget_ops[w->id].ipc_unprepare) {
1095+
struct snd_sof_widget *pipe_widget = swidget->spipe->pipe_widget;
1096+
10891097
/* unprepare the source widget */
10901098
widget_ops[w->id].ipc_unprepare(swidget);
10911099

1100+
/* unprepare the widget's pipeline widget */
1101+
widget_ops[pipe_widget->id].ipc_unprepare(pipe_widget);
1102+
}
1103+
10921104
swidget->prepared = false;
10931105

10941106
unprepare:

0 commit comments

Comments
 (0)