From a102e66440c7579e9a82ee869b7dc7a53393e3df Mon Sep 17 00:00:00 2001 From: Tanu Kaskinen Date: Tue, 17 Feb 2015 21:15:22 +0200 Subject: [PATCH] ucm: fix the logic of choosing the default cdev If the cdev has not been configured explicitly, use the PlaybackCTL or CaptureCTL value if one of them is set. If neither are set, or if both are set to different values, then there's no sensible default, so executing the sequence should fail. The previous code probably tried to implement this logic, but it was buggy. Also use more descriptive variable names than "cdev1" and "cdev2". Signed-off-by: Tanu Kaskinen Signed-off-by: Takashi Iwai --- src/ucm/main.c | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/src/ucm/main.c b/src/ucm/main.c index efb5be5d..81a0950e 100644 --- a/src/ucm/main.c +++ b/src/ucm/main.c @@ -299,8 +299,10 @@ static int execute_sequence(snd_use_case_mgr_t *uc_mgr, case SEQUENCE_ELEMENT_TYPE_CSET: case SEQUENCE_ELEMENT_TYPE_CSET_BIN_FILE: if (cdev == NULL) { - const char *cdev1 = NULL, *cdev2 = NULL; - err = get_value3(&cdev1, "PlaybackCTL", + const char *playback_ctl = NULL; + const char *capture_ctl = NULL; + + err = get_value3(&playback_ctl, "PlaybackCTL", value_list1, value_list2, value_list3); @@ -308,23 +310,33 @@ static int execute_sequence(snd_use_case_mgr_t *uc_mgr, uc_error("cdev is not defined!"); return err; } - err = get_value3(&cdev2, "CaptureCTL", + err = get_value3(&capture_ctl, "CaptureCTL", value_list1, value_list2, value_list3); if (err < 0 && err != -ENOENT) { - free((char *)cdev1); + free((char *)playback_ctl); uc_error("cdev is not defined!"); return err; } - if (cdev1 == NULL || cdev2 == NULL || - strcmp(cdev1, cdev2) == 0) { - cdev = (char *)cdev1; - free((char *)cdev2); - } else { - free((char *)cdev1); - free((char *)cdev2); + if (playback_ctl == NULL && + capture_ctl == NULL) { + uc_error("cdev is not defined!"); + return -EINVAL; + } + if (playback_ctl != NULL && + capture_ctl != NULL && + strcmp(playback_ctl, capture_ctl) != 0) { + free((char *)playback_ctl); + free((char *)capture_ctl); + uc_error("cdev is not defined!"); + return -EINVAL; } + if (playback_ctl != NULL) { + cdev = (char *)playback_ctl; + free((char *)capture_ctl); + } else + cdev = (char *)capture_ctl; } if (ctl == NULL) { err = open_ctl(uc_mgr, &ctl, cdev); -- 2.47.1