From f0852a480cd564b58eaa119198971c5dbb891729 Mon Sep 17 00:00:00 2001 From: Kai Vehmanen Date: Mon, 5 Oct 2026 19:29:39 +0300 Subject: [PATCH] topology: alsatplg: add double-expansion for global defines Add support for following definition for global variables: IncludeByKey.SDW_DMIC_PCM_CHANNELS { "1" { Define { SDW_DMIC_CHANNEL_CFG $CHANNEL_CONFIG_MONO } } } This doesn't currently work as the pre-processor merges the nested Define into the global define registry as a STRING value ("$CHANNEL_CONFIG_MONO"). Later, during object attribute expansion, pre_process_object_variables_expand_fcn finds the variable in the global defines and returns immediately with that unresolved string. The caller then passes "$CHANNEL_CONFIG_MONO" to the token encoder, which cannot parse it as an integer and silently substitutes 0. Add support for double expansion for such global defines. This is similar to how local variables are already handled (see commit 0029ab7cc7c7 ("topology: Expand attribute references inside $[] expressions")), and will help to reduce repeated IncludeByKey statements in topology files. Signed-off-by: Kai Vehmanen --- topology/pre-process-object.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/topology/pre-process-object.c b/topology/pre-process-object.c index d7649077..853e6cba 100644 --- a/topology/pre-process-object.c +++ b/topology/pre-process-object.c @@ -1612,8 +1612,20 @@ pre_process_object_variables_expand_fcn(snd_config_t **dst, const char *str, voi /* find variable from global definitions first */ ret = pre_process_find_variable(dst, str, conf_defines); - if (ret >= 0) + if (ret >= 0) { + /* the value may itself be a $VAR reference (e.g. from a nested Define + * inside an IncludeByKey branch) — expand it before returning */ + if (snd_config_get_string(*dst, &val) >= 0 && val[0] == '$') { + char *var = strdup(val); + + snd_config_delete(*dst); + ret = snd_config_evaluate_string(dst, var, + pre_process_object_variables_expand_fcn, + tplg_pp); + free(var); + } return ret; + } /* No global define found, proceeed to object attribute search */ if (snd_config_get_id(object_cfg, &object_id) < 0)