From c895dae93c2ce00f8d70ff57ae38744126fc1dbc Mon Sep 17 00:00:00 2001 From: Bard liao Date: Mon, 7 Jan 2019 20:51:03 +0800 Subject: [PATCH 1/3] ASoC: SOF: topology: check no_pcm in sof_link_unload We only handle BE links in sof_link_load. So we should only handle BE link in sof_link_unload, too. Signed-off-by: Bard liao --- sound/soc/sof/topology.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/sound/soc/sof/topology.c b/sound/soc/sof/topology.c index 7da41f06e1d313..d43b3e3107b0fe 100644 --- a/sound/soc/sof/topology.c +++ b/sound/soc/sof/topology.c @@ -2446,6 +2446,10 @@ static int sof_link_unload(struct snd_soc_component *scomp, struct snd_sof_dai *sof_dai = NULL; int ret = 0; + /* only BE link is loaded by sof */ + if (!link->no_pcm) + return 0; + list_for_each_entry(sof_dai, &sdev->dai_list, list) { if (!sof_dai->name) continue; From fae9cc796f167cbafaed20bd22fc8026e7193f83 Mon Sep 17 00:00:00 2001 From: Bard liao Date: Thu, 10 Jan 2019 01:20:41 +0800 Subject: [PATCH 2/3] ASoC: topology: fix memory leak in soc_tplg_dapm_widget_create template.sname and template.name are only freed when an error occur. They should be freed in the success return case, too. Signed-off-by: Bard liao --- sound/soc/soc-topology.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sound/soc/soc-topology.c b/sound/soc/soc-topology.c index b98913249dbe8b..a697e5552d4815 100644 --- a/sound/soc/soc-topology.c +++ b/sound/soc/soc-topology.c @@ -1651,6 +1651,9 @@ static int soc_tplg_dapm_widget_create(struct soc_tplg *tplg, if (ret < 0) goto ready_err; + kfree(template.sname); + kfree(template.name); + return 0; ready_err: From d5d2cdd343d81c20e176416700cd0e14f85612d3 Mon Sep 17 00:00:00 2001 From: Bard liao Date: Mon, 7 Jan 2019 06:24:02 +0800 Subject: [PATCH 3/3] ASoC: topology: unload physical dai link in remove soc_tplg_link_config() will find the physical dai link and call soc_tplg_dai_link_load() to load the BE dai link. Currently remove_link() is only used to remove the FE dai link which is created by the topology. The BE dai link cannot however be unloaded in snd_soc_tplg_component _remove(), which is problematic if anything needs to be released or reinitialized. This patch aligns the definitions of dynamic types with the existing UAPI and adds a new remove_backend_link() routine to unload the the BE dai link when snd_soc_tplg_component_remove() is invoked. Signed-off-by: Bard liao --- include/sound/soc-topology.h | 1 + sound/soc/soc-topology.c | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/include/sound/soc-topology.h b/include/sound/soc-topology.h index 8c43cfc240fa33..5223896de26f51 100644 --- a/include/sound/soc-topology.h +++ b/include/sound/soc-topology.h @@ -45,6 +45,7 @@ enum snd_soc_dobj_type { SND_SOC_DOBJ_DAI_LINK, SND_SOC_DOBJ_PCM, SND_SOC_DOBJ_CODEC_LINK, + SND_SOC_DOBJ_BACKEND_LINK, }; /* dynamic control object */ diff --git a/sound/soc/soc-topology.c b/sound/soc/soc-topology.c index a697e5552d4815..9bff5f2d533c81 100644 --- a/sound/soc/soc-topology.c +++ b/sound/soc/soc-topology.c @@ -559,6 +559,24 @@ static void remove_link(struct snd_soc_component *comp, kfree(link); } +/* unload dai link */ +static void remove_backend_link(struct snd_soc_component *comp, + struct snd_soc_dobj *dobj, int pass) +{ + if (pass != SOC_TPLG_PASS_LINK) + return; + + if (dobj->ops && dobj->ops->link_unload) + dobj->ops->link_unload(comp, dobj); + + /* + * We don't free the link here as what remove_link() do since BE + * links are not allocated by topology. + */ + + list_del(&dobj->list); +} + /* bind a kcontrol to it's IO handlers */ static int soc_tplg_kcontrol_bind_io(struct snd_soc_tplg_ctl_hdr *hdr, struct snd_kcontrol_new *k, @@ -2164,6 +2182,12 @@ static int soc_tplg_link_config(struct soc_tplg *tplg, return ret; } + /* for unloading it in snd_soc_tplg_component_remove */ + link->dobj.index = tplg->index; + link->dobj.ops = tplg->ops; + link->dobj.type = SND_SOC_DOBJ_BACKEND_LINK; + list_add(&link->dobj.list, &tplg->comp->dobj_list); + return 0; } @@ -2650,6 +2674,13 @@ int snd_soc_tplg_component_remove(struct snd_soc_component *comp, u32 index) case SND_SOC_DOBJ_DAI_LINK: remove_link(comp, dobj, pass); break; + case SND_SOC_DOBJ_BACKEND_LINK: + /* + * call link_unload ops if extra + * deinitialization is needed. + */ + remove_backend_link(comp, dobj, pass); + break; default: dev_err(comp->dev, "ASoC: invalid component type %d for removal\n", dobj->type);