From patchwork Tue Feb 17 19:15:22 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tanu Kaskinen X-Patchwork-Id: 5841041 Return-Path: X-Original-To: patchwork-alsa-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 471679F30C for ; Tue, 17 Feb 2015 19:15:59 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 6FC45201F2 for ; Tue, 17 Feb 2015 19:15:58 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.kernel.org (Postfix) with ESMTP id 49C31201D3 for ; Tue, 17 Feb 2015 19:15:56 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id E14F92616B9; Tue, 17 Feb 2015 20:15:53 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Received: from alsa0.perex.cz (localhost [IPv6:::1]) by alsa0.perex.cz (Postfix) with ESMTP id 499E9261629; Tue, 17 Feb 2015 20:15:46 +0100 (CET) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa0.perex.cz (Postfix, from userid 1000) id 8794826164D; Tue, 17 Feb 2015 20:15:44 +0100 (CET) Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by alsa0.perex.cz (Postfix) with ESMTP id 81BFA261615 for ; Tue, 17 Feb 2015 20:15:37 +0100 (CET) Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga103.fm.intel.com with ESMTP; 17 Feb 2015 11:08:04 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.09,595,1418112000"; d="scan'208";a="528807939" Received: from whryniew-mobl1.ger.corp.intel.com (HELO tkkaskin-mobl3.ger.corp.intel.com.ger.corp.intel.com) ([10.252.19.56]) by orsmga003.jf.intel.com with ESMTP; 17 Feb 2015 11:06:53 -0800 From: Tanu Kaskinen To: alsa-devel@alsa-project.org Date: Tue, 17 Feb 2015 21:15:22 +0200 Message-Id: <1424200523-6314-3-git-send-email-tanu.kaskinen@linux.intel.com> X-Mailer: git-send-email 1.9.3 In-Reply-To: <1424200523-6314-1-git-send-email-tanu.kaskinen@linux.intel.com> References: <1424200523-6314-1-git-send-email-tanu.kaskinen@linux.intel.com> Cc: Takashi Iwai , Liam Girdwood Subject: [alsa-devel] [PATCH 2/3] ucm: fix the logic of choosing the default cdev X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- 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 efb5be5..81a0950 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);