From b5748d329bae8d1d4cf311193f7e9df3396a99a0 Mon Sep 17 00:00:00 2001 From: Jaroslav Kysela Date: Fri, 28 Jan 2022 18:53:39 +0100 Subject: [PATCH] topology: use a copy of the command line defines Fixes: a9b3525 ("topology: don't fail when Define section is missing in the included file") Signed-off-by: Jaroslav Kysela --- topology/pre-processor.c | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/topology/pre-processor.c b/topology/pre-processor.c index f32f80c..3a227e3 100644 --- a/topology/pre-processor.c +++ b/topology/pre-processor.c @@ -249,7 +249,7 @@ static int pre_process_set_defines(struct tplg_pre_processor *tplg_pp, const cha static int pre_process_add_defines(struct tplg_pre_processor *tplg_pp, snd_config_t *from) { - snd_config_t *conf_defines; + snd_config_t *conf_defines, *conf_tmp; int ret; ret = snd_config_search(from, "Define", &conf_defines); @@ -280,16 +280,6 @@ create: return ret; } - /* - * merge the command line defines with the variables in the conf file to override - * default values - */ - ret = snd_config_merge(conf_defines, tplg_pp->define_cfg, true); - if (ret < 0) { - fprintf(stderr, "Failed to override variable definitions\n"); - return ret; - } - if (tplg_pp->define_cfg_merged != conf_defines) { /* * merge back to the main configuration tree (Define subtree) @@ -301,6 +291,22 @@ create: } } + /* + * merge the command line defines with the variables in the conf file to override + * default values; use a copy (merge deletes the source tree) + */ + ret = snd_config_copy(&conf_tmp, tplg_pp->define_cfg); + if (ret < 0) { + fprintf(stderr, "Failed to copy variable definitions\n"); + return ret; + } + ret = snd_config_merge(tplg_pp->define_cfg_merged, conf_tmp, true); + if (ret < 0) { + fprintf(stderr, "Failed to override variable definitions\n"); + snd_config_delete(conf_tmp); + return ret; + } + return 0; } -- 2.47.1