diff mbox series

ASoC: topology: free created components in tplg load error

Message ID 20190217132347.12593-1-yung-chuan.liao@linux.intel.com (mailing list archive)
State Accepted
Commit 304017d31df36fb61eb2ed3ebf65fb6870b3c731
Headers show
Series ASoC: topology: free created components in tplg load error | expand

Commit Message

Bard Liao Feb. 17, 2019, 1:23 p.m. UTC
Topology resources are no longer needed if any element failed to load.

Signed-off-by: Bard liao <yung-chuan.liao@linux.intel.com>
---
 sound/soc/soc-topology.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

Comments

Pierre-Louis Bossart Feb. 19, 2019, 3:28 p.m. UTC | #1
On 2/17/19 7:23 AM, Bard liao wrote:
> Topology resources are no longer needed if any element failed to load.
>
> Signed-off-by: Bard liao <yung-chuan.liao@linux.intel.com>

Acked-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>


> ---
>   sound/soc/soc-topology.c | 8 +++++++-
>   1 file changed, 7 insertions(+), 1 deletion(-)
>
> diff --git a/sound/soc/soc-topology.c b/sound/soc/soc-topology.c
> index c5638e15a2dd..25fca7055464 100644
> --- a/sound/soc/soc-topology.c
> +++ b/sound/soc/soc-topology.c
> @@ -2587,6 +2587,7 @@ int snd_soc_tplg_component_load(struct snd_soc_component *comp,
>   	struct snd_soc_tplg_ops *ops, const struct firmware *fw, u32 id)
>   {
>   	struct soc_tplg tplg;
> +	int ret;
>   
>   	/* setup parsing context */
>   	memset(&tplg, 0, sizeof(tplg));
> @@ -2600,7 +2601,12 @@ int snd_soc_tplg_component_load(struct snd_soc_component *comp,
>   	tplg.bytes_ext_ops = ops->bytes_ext_ops;
>   	tplg.bytes_ext_ops_count = ops->bytes_ext_ops_count;
>   
> -	return soc_tplg_load(&tplg);
> +	ret = soc_tplg_load(&tplg);
> +	/* free the created components if fail to load topology */
> +	if (ret)
> +		snd_soc_tplg_component_remove(comp, SND_SOC_TPLG_INDEX_ALL);
> +
> +	return ret;
>   }
>   EXPORT_SYMBOL_GPL(snd_soc_tplg_component_load);
>
diff mbox series

Patch

diff --git a/sound/soc/soc-topology.c b/sound/soc/soc-topology.c
index c5638e15a2dd..25fca7055464 100644
--- a/sound/soc/soc-topology.c
+++ b/sound/soc/soc-topology.c
@@ -2587,6 +2587,7 @@  int snd_soc_tplg_component_load(struct snd_soc_component *comp,
 	struct snd_soc_tplg_ops *ops, const struct firmware *fw, u32 id)
 {
 	struct soc_tplg tplg;
+	int ret;
 
 	/* setup parsing context */
 	memset(&tplg, 0, sizeof(tplg));
@@ -2600,7 +2601,12 @@  int snd_soc_tplg_component_load(struct snd_soc_component *comp,
 	tplg.bytes_ext_ops = ops->bytes_ext_ops;
 	tplg.bytes_ext_ops_count = ops->bytes_ext_ops_count;
 
-	return soc_tplg_load(&tplg);
+	ret = soc_tplg_load(&tplg);
+	/* free the created components if fail to load topology */
+	if (ret)
+		snd_soc_tplg_component_remove(comp, SND_SOC_TPLG_INDEX_ALL);
+
+	return ret;
 }
 EXPORT_SYMBOL_GPL(snd_soc_tplg_component_load);