From patchwork Wed Jul 13 08:44:54 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: mengdong.lin@linux.intel.com X-Patchwork-Id: 9227131 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 29E646075D for ; Wed, 13 Jul 2016 08:43:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 19D1C272AA for ; Wed, 13 Jul 2016 08:43:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0E74127813; Wed, 13 Jul 2016 08:43:58 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 239522766D for ; Wed, 13 Jul 2016 08:43:57 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id 007E62666E2; Wed, 13 Jul 2016 10:43:55 +0200 (CEST) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id 9E108266541; Wed, 13 Jul 2016 10:41:27 +0200 (CEST) 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 3BE66266549; Wed, 13 Jul 2016 10:41:26 +0200 (CEST) Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by alsa0.perex.cz (Postfix) with ESMTP id F18EF26656A for ; Wed, 13 Jul 2016 10:40:19 +0200 (CEST) Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga101.fm.intel.com with ESMTP; 13 Jul 2016 01:39:59 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos; i="5.28,356,1464678000"; d="scan'208"; a="1005861865" Received: from amanda-haswell-pc.sh.intel.com ([10.239.159.169]) by fmsmga001.fm.intel.com with ESMTP; 13 Jul 2016 01:39:57 -0700 From: mengdong.lin@linux.intel.com To: alsa-devel@alsa-project.org, broonie@kernel.org Date: Wed, 13 Jul 2016 16:44:54 +0800 Message-Id: X-Mailer: git-send-email 2.5.0 In-Reply-To: References: Cc: Mengdong Lin , tiwai@suse.de, mengdong.lin@intel.com, liam.r.girdwood@intel.com, shreyas.nc@intel.com Subject: [alsa-devel] [PATCH 3/5] topology: Change uuid value to 16 separate characters in text conf file 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 From: Mengdong Lin Previously in text conf file, the uuid value of vendor tuples is a 16-characer string. Now change it to 16 characters separated by commas, easier for users to edit it manually. Signed-off-by: Mengdong Lin diff --git a/include/topology.h b/include/topology.h index d666505..89bed6c 100644 --- a/include/topology.h +++ b/include/topology.h @@ -273,8 +273,8 @@ extern "C" { * ... * } * - * tuples."uuid" { - * VENDOR_TOKEN_ID2 "16 character uuid" + * tuples."uuid" { # 16 characters separated by commas + * VENDOR_TOKEN_ID2 "0x01,0x02,...,0x0f" * ... * } * diff --git a/src/topology/data.c b/src/topology/data.c index 7ff178f..65054d7 100644 --- a/src/topology/data.c +++ b/src/topology/data.c @@ -176,6 +176,49 @@ static int get_hex_num(const char *str) return values; } +/* get uuid from a string made by 16 characters separated by commas */ +static int get_uuid(const char *str, unsigned char *uuid_le) +{ + unsigned long int val; + char *tmp, *s = NULL; + int values = 0, ret = 0; + + tmp = strdup(str); + if (tmp == NULL) + return -ENOMEM; + + s = strtok(tmp, ","); + + while (s != NULL) { + errno = 0; + val = strtoul(s, NULL, 0); + if ((errno == ERANGE && (val == LONG_MAX || val == LONG_MIN)) + || (errno != 0 && val == 0) + || (val > UCHAR_MAX)) { + SNDERR("error: invalid value for uuid\n"); + ret = -EINVAL; + goto out; + } + + *(uuid_le + values) = (unsigned char)val; + + values++; + if (values >= 16) + break; + + s = strtok(NULL, ","); + } + + if (values < 16) { + SNDERR("error: less than 16 integers for uuid\n"); + ret = -EINVAL; + } + +out: + free(tmp); + return ret; +} + static int write_hex(char *buf, char *str, int width) { long val; @@ -536,14 +579,8 @@ static int parse_tuple_set(snd_tplg_t *tplg, snd_config_t *cfg, switch (type) { case SND_SOC_TPLG_TUPLE_TYPE_UUID: - len = strlen(value); - if (len > 16 || len == 0) { - SNDERR("error: tuple %s: invalid uuid\n", id); + if (get_uuid(value, tuple->uuid) < 0) goto err; - } - - memcpy(tuple->uuid, value, len); - tplg_dbg("\t\t%s = %s\n", tuple->token, tuple->uuid); break; case SND_SOC_TPLG_TUPLE_TYPE_STRING: