From patchwork Tue Feb 10 20:42:34 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tanu Kaskinen X-Patchwork-Id: 5808931 Return-Path: X-Original-To: patchwork-alsa-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 064A0BF440 for ; Tue, 10 Feb 2015 20:44:14 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 22BF020173 for ; Tue, 10 Feb 2015 20:44:13 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.kernel.org (Postfix) with ESMTP id DB2D92012E for ; Tue, 10 Feb 2015 20:44:11 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id 0D063261A01; Tue, 10 Feb 2015 21:44:11 +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 2D640261586; Tue, 10 Feb 2015 21:42:54 +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 AAF81261522; Tue, 10 Feb 2015 21:42:50 +0100 (CET) Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by alsa0.perex.cz (Postfix) with ESMTP id DC8EE26057A for ; Tue, 10 Feb 2015 21:42:45 +0100 (CET) Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga101.jf.intel.com with ESMTP; 10 Feb 2015 12:42:43 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.09,552,1418112000"; d="scan'208";a="650259914" Received: from tkkaskin-mobl3.ger.corp.intel.com (HELO tkkaskin-mobl3.ger.corp.intel.com.ger.corp.intel.com) ([10.252.8.251]) by orsmga001.jf.intel.com with ESMTP; 10 Feb 2015 12:42:42 -0800 From: Tanu Kaskinen To: alsa-devel@alsa-project.org Date: Tue, 10 Feb 2015 22:42:34 +0200 Message-Id: <1423600954-8751-4-git-send-email-tanu.kaskinen@linux.intel.com> X-Mailer: git-send-email 1.9.3 In-Reply-To: <1423600954-8751-1-git-send-email-tanu.kaskinen@linux.intel.com> References: <1423600954-8751-1-git-send-email-tanu.kaskinen@linux.intel.com> Cc: tiwai@suse.de, liam.r.girdwood@linux.intel.com Subject: [alsa-devel] [PATCH 3/3] ucm: fix inappropriate use of const 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 The caller is expected to free the string returned by snd_use_case_get(), but for some reason the string is marked as const, so the caller is forced to do type casting to get rid of compiler warnings. I don't see any reason for using const in snd_use_case_get(), so let's remove that. This will cause warnings in application code, if applications currently pass const variables to the function, which they very likely do. I don't know if that's acceptable. If not, then it's too late to fix this bug... --- include/use-case.h | 2 +- src/ucm/main.c | 24 ++++++++++++------------ 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/include/use-case.h b/include/use-case.h index f30168f..28d786f 100644 --- a/include/use-case.h +++ b/include/use-case.h @@ -286,7 +286,7 @@ int snd_use_case_get_list(snd_use_case_mgr_t *uc_mgr, */ int snd_use_case_get(snd_use_case_mgr_t *uc_mgr, const char *identifier, - const char **value); + char **value); /** * \brief Get current - integer diff --git a/src/ucm/main.c b/src/ucm/main.c index 62bc374..8fbf94f 100644 --- a/src/ucm/main.c +++ b/src/ucm/main.c @@ -40,9 +40,9 @@ * misc */ -static int get_value1(const char **value, struct list_head *value_list, +static int get_value1(char **value, struct list_head *value_list, const char *identifier); -static int get_value3(const char **value, +static int get_value3(char **value, const char *identifier, struct list_head *value_list1, struct list_head *value_list2, @@ -299,7 +299,7 @@ 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; + char *cdev1 = NULL, *cdev2 = NULL; err = get_value3(&cdev1, "PlaybackCTL", value_list1, value_list2, @@ -313,7 +313,7 @@ static int execute_sequence(snd_use_case_mgr_t *uc_mgr, value_list2, value_list3); if (err < 0 && err != ENOENT) { - free((char *)cdev1); + free(cdev1); uc_error("cdev is not defined!"); return err; } @@ -327,11 +327,11 @@ static int execute_sequence(snd_use_case_mgr_t *uc_mgr, * before calling open_ctl()). */ if (cdev1 == NULL || cdev2 == NULL || strcmp(cdev1, cdev2) == 0) { - cdev = (char *)cdev1; - free((char *)cdev2); + cdev = cdev1; + free(cdev2); } else { - free((char *)cdev1); - free((char *)cdev2); + free(cdev1); + free(cdev2); } } if (ctl == NULL) { @@ -1233,7 +1233,7 @@ int snd_use_case_get_list(snd_use_case_mgr_t *uc_mgr, return err; } -static int get_value1(const char **value, struct list_head *value_list, +static int get_value1(char **value, struct list_head *value_list, const char *identifier) { struct ucm_value *val; @@ -1254,7 +1254,7 @@ static int get_value1(const char **value, struct list_head *value_list, return -ENOENT; } -static int get_value3(const char **value, +static int get_value3(char **value, const char *identifier, struct list_head *value_list1, struct list_head *value_list2, @@ -1284,7 +1284,7 @@ static int get_value3(const char **value, */ static int get_value(snd_use_case_mgr_t *uc_mgr, const char *identifier, - const char **value, + char **value, const char *mod_dev_name, const char *verb_name, int exact) @@ -1354,7 +1354,7 @@ static int get_value(snd_use_case_mgr_t *uc_mgr, */ int snd_use_case_get(snd_use_case_mgr_t *uc_mgr, const char *identifier, - const char **value) + char **value) { const char *slash1, *slash2, *mod_dev_after; const char *ident, *mod_dev, *verb;