Skip to contentSkip to conversation

ucm: Allow empty strings in "${var:...}" substitutions

PATCH In review Hans de Goede 3 participants 3 messages Jun 27, 2020 – Jun 28, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ucm: Allow empty strings in "${var:...}" substitutions

Recent ucm-conf changes introduce checks like this one in various places:

If.mspk {
        Condition {
                Type String
                Empty "${var:MonoSpeaker}"
        }
        True ...
        False ...
}

The 'Empty "${var:MonoSpeaker}"' part can only every succeed if we do:

Define.MonoSpeaker ""

But so far that would result in an error like this one:

ALSA lib ucm_subs.c:367:(uc_mgr_get_substituted_value) variable '${var:MonoSpeaker}' is not defined in this context! ALSA lib main.c:983:(snd_use_case_mgr_open) error: failed to import cht-bsw-rt5672 use case configuration -22
alsaucm: error failed to open sound card cht-bsw-rt5672: Invalid argument

This commit fixes this by allowing empty values for "${var:...}" substitutions.

---
Note besides the mentioned error, this also fixes similar errors I have been seeing on every board since alsa-ucm-conf commit d001c8de287f ("ucm.conf: add support for the kernel module name tree")

---
 src/ucm/ucm_subs.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)
src/ucm/ucm_subs.c +7 -6
index 293426f2..a154aa51 100644
@@ -262,9 +262,10 @@ static char *rval_var(snd_use_case_mgr_t *uc_mgr, const char *id)
 		goto __rval;						\
 	}
 
-#define MATCH_VARIABLE2(name, id, fcn)					\
+#define MATCH_VARIABLE2(name, id, fcn, empty_ok)			\
 	if (strncmp((name), (id), sizeof(id) - 1) == 0) {		\
 		idsize = sizeof(id) - 1;				\
+		allow_empty = (empty_ok);				\
 		fcn2 = (fcn);						\
 		goto __match2;						\
 	}
@@ -314,11 +315,11 @@ __std:
 		MATCH_VARIABLE(value, "${CardName}", rval_card_name, false);
 		MATCH_VARIABLE(value, "${CardLongName}", rval_card_longname, false);
 		MATCH_VARIABLE(value, "${CardComponents}", rval_card_components, true);
-		MATCH_VARIABLE2(value, "${env:", rval_env);
-		MATCH_VARIABLE2(value, "${sys:", rval_sysfs);
-		MATCH_VARIABLE2(value, "${var:", rval_var);
-		MATCH_VARIABLE2(value, "${CardNumberByName:", rval_card_number_by_name);
-		MATCH_VARIABLE2(value, "${CardIdByName:", rval_card_id_by_name);
+		MATCH_VARIABLE2(value, "${env:", rval_env, false);
+		MATCH_VARIABLE2(value, "${sys:", rval_sysfs, false);
+		MATCH_VARIABLE2(value, "${var:", rval_var, true);
+		MATCH_VARIABLE2(value, "${CardNumberByName:", rval_card_number_by_name, false);
+		MATCH_VARIABLE2(value, "${CardIdByName:", rval_card_id_by_name, false);
 __merr:
 		err = -EINVAL;
 		tmp = strchr(value, '}');
Signature · 1 line
2.26.2
Tested-by on v1 1/1
#1 lore raw
Quoted 21 lines · Hans de Goede

Recent ucm-conf changes introduce checks like this one in various places:

If.mspk {
         Condition {
                 Type String
                 Empty "${var:MonoSpeaker}"
         }
         True ...
         False ...
}

The 'Empty "${var:MonoSpeaker}"' part can only every succeed if we do:

Define.MonoSpeaker ""

But so far that would result in an error like this one:

ALSA lib ucm_subs.c:367:(uc_mgr_get_substituted_value) variable '${var:MonoSpeaker}' is not defined in this context! ALSA lib main.c:983:(snd_use_case_mgr_open) error: failed to import cht-bsw-rt5672 use case configuration -22
alsaucm: error failed to open sound card cht-bsw-rt5672: Invalid argument

Quoted 8 lines

This commit fixes this by allowing empty values for "${var:...}" substitutions.

---
Note besides the mentioned error, this also fixes similar errors I have been seeing on every board since alsa-ucm-conf commit d001c8de287f ("ucm.conf: add support for the kernel module name tree")

Well this is quite timely, I had to revert to older versions of UCM earlier today because of similar issues:

root@Zotac:~/alsa-lib# alsaucm -c SOF set _verb HiFi set _enadev Headphones
ALSA lib ucm_subs.c:367:(uc_mgr_get_substituted_value) variable '${var:V1}' is not defined in this context!
ALSA lib main.c:983:(snd_use_case_mgr_open) error: failed to import SOF use case configuration -22
alsaucm: error failed to open sound card SOF: Invalid argument

This error is gone with this patch + latest alsa-ucm-conf, so

Thanks Hans!

Quoted 38 lines
---
  src/ucm/ucm_subs.c | 13 +++++++------
  1 file changed, 7 insertions(+), 6 deletions(-)
src/ucm/ucm_subs.c +7 -6
index 293426f2..a154aa51 100644
@@ -262,9 +262,10 @@ static char *rval_var(snd_use_case_mgr_t *uc_mgr, const char *id)
  		goto __rval;						\
  	}
 
-#define MATCH_VARIABLE2(name, id, fcn)					\
+#define MATCH_VARIABLE2(name, id, fcn, empty_ok)			\
  	if (strncmp((name), (id), sizeof(id) - 1) == 0) {		\
  		idsize = sizeof(id) - 1;				\
+		allow_empty = (empty_ok);				\
  		fcn2 = (fcn);						\
  		goto __match2;						\
  	}
@@ -314,11 +315,11 @@ __std:
  		MATCH_VARIABLE(value, "${CardName}", rval_card_name, false);
  		MATCH_VARIABLE(value, "${CardLongName}", rval_card_longname, false);
  		MATCH_VARIABLE(value, "${CardComponents}", rval_card_components, true);
-		MATCH_VARIABLE2(value, "${env:", rval_env);
-		MATCH_VARIABLE2(value, "${sys:", rval_sysfs);
-		MATCH_VARIABLE2(value, "${var:", rval_var);
-		MATCH_VARIABLE2(value, "${CardNumberByName:", rval_card_number_by_name);
-		MATCH_VARIABLE2(value, "${CardIdByName:", rval_card_id_by_name);
+		MATCH_VARIABLE2(value, "${env:", rval_env, false);
+		MATCH_VARIABLE2(value, "${sys:", rval_sysfs, false);
+		MATCH_VARIABLE2(value, "${var:", rval_var, true);
+		MATCH_VARIABLE2(value, "${CardNumberByName:", rval_card_number_by_name, false);
+		MATCH_VARIABLE2(value, "${CardIdByName:", rval_card_id_by_name, false);
  __merr:
  		err = -EINVAL;
  		tmp = strchr(value, '}');
#2 lore raw
In reply to Hans de Goede

Dne 27. 06. 20 v 20:30 Hans de Goede napsal(a):

Quoted 17 lines

Recent ucm-conf changes introduce checks like this one in various places:

If.mspk {
         Condition {
                 Type String
                 Empty "${var:MonoSpeaker}"
         }
         True ...
         False ...
}

The 'Empty "${var:MonoSpeaker}"' part can only every succeed if we do:

Define.MonoSpeaker ""

But so far that would result in an error like this one:

Quoted 8 lines

ALSA lib ucm_subs.c:367:(uc_mgr_get_substituted_value) variable '${var:MonoSpeaker}' is not defined in this context! ALSA lib main.c:983:(snd_use_case_mgr_open) error: failed to import cht-bsw-rt5672 use case configuration -22
alsaucm: error failed to open sound card cht-bsw-rt5672: Invalid argument

This commit fixes this by allowing empty values for "${var:...}" substitutions.

Mea culpa. I had this change in my local tree, but I forgot to push it upstream. Anyway, thank you for your work and testing. I accepted your commit to retain your credits.

Jaroslav

Signature · 2 lines
Jaroslav Kysela <[email protected]>
Linux Sound Maintainer; ALSA Project; Red Hat, Inc.