alsa/0036-topology-add-tplg_get_unsigned-function.patch

173 lines
4.9 KiB
Diff
Raw Normal View History

Accepting request 766329 from home:tiwai:branches:multimedia:libs - Backport upstream fixes: more topology fixes, a memory leak fix in mixer API, alsactl string handling fix, UCM config fixes: 0032-Update-the-attributes.m4-macro-file-from-xine.patch 0033-topology-avoid-to-use-the-atoi-directly-when-expecte.patch 0034-topology-use-snd_config_get_bool-instead-own-impleme.patch 0035-topology-fix-tplg_get_integer-handle-errno-ERANGE.patch 0036-topology-add-tplg_get_unsigned-function.patch 0037-topology-convert-builder-to-use-the-mallocated-memor.patch 0038-topology-add-binary-output-from-the-builder.patch 0039-topology-parser-recode-tplg_parse_config.patch 0040-topology-add-snd_tplg_load-remove-snd_tplg_build_bin.patch 0041-topology-move-the-topology-element-table-from-builde.patch 0042-topology-add-parser-to-the-tplg_table.patch 0043-topology-add-snd_tplg_save.patch 0044-topology-add-snd_tplg_create-with-flags.patch 0045-topology-add-snd_tplg_version-function.patch 0046-topology-cleanup-the-SNDERR-calls.patch 0047-topology-dapm-fix-the-SNDERR-Undefined.patch 0048-topology-fix-the-unitialized-tuples.patch 0049-topology-implement-shorter-hexa-uuid-00-00-parser.patch 0050-topology-fix-the-TPLG_DEBUG-compilation.patch 0051-topology-fix-the-ops-parser-accept-integer-hexa-valu.patch 0052-topology-fix-the-wrong-memory-access-object-realloc.patch 0053-topology-implement-snd_tplg_decode.patch 0054-topology-move-the-elem-list-delete-to-tplg_elem_free.patch 0055-topology-unify-the-log-mechanism.patch 0056-topology-tplg_dbg-cleanups.patch 0057-topology-cosmetic-changes-functions.patch 0058-mixer-Fix-memory-leak-for-more-than-16-file-descript.patch OBS-URL: https://build.opensuse.org/request/show/766329 OBS-URL: https://build.opensuse.org/package/show/multimedia:libs/alsa?expand=0&rev=265
2020-01-22 14:27:43 +00:00
From 14e43a11873d14ec6f16967c83629237ef44ac38 Mon Sep 17 00:00:00 2001
From: Jaroslav Kysela <perex@perex.cz>
Date: Sat, 14 Dec 2019 14:05:49 +0100
Subject: [PATCH 36/63] topology: add tplg_get_unsigned() function
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
---
src/topology/data.c | 19 +++++--------------
src/topology/parser.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++
src/topology/pcm.c | 13 ++-----------
src/topology/tplg_local.h | 1 +
4 files changed, 55 insertions(+), 25 deletions(-)
diff --git a/src/topology/data.c b/src/topology/data.c
index 6b1337b39bad..9807445e8c37 100644
--- a/src/topology/data.c
+++ b/src/topology/data.c
@@ -556,7 +556,7 @@ static int parse_tuple_set(snd_config_t *cfg,
struct tplg_tuple_set *set;
unsigned int type, num_tuples = 0;
struct tplg_tuple *tuple;
- unsigned long int tuple_val;
+ unsigned int tuple_val;
int ival;
snd_config_get_id(cfg, &id);
@@ -598,10 +598,6 @@ static int parse_tuple_set(snd_config_t *cfg,
if (snd_config_get_id(n, &id) < 0)
continue;
- /* get value */
- if (snd_config_get_string(n, &value) < 0)
- continue;
-
tuple = &set->tuple[set->num_tuples];
snd_strlcpy(tuple->token, id,
SNDRV_CTL_ELEM_ID_NAME_MAXLEN);
@@ -633,14 +629,9 @@ static int parse_tuple_set(snd_config_t *cfg,
case SND_SOC_TPLG_TUPLE_TYPE_BYTE:
case SND_SOC_TPLG_TUPLE_TYPE_SHORT:
case SND_SOC_TPLG_TUPLE_TYPE_WORD:
- if (snd_config_get_string(n, &value) < 0)
- continue;
- errno = 0;
- /* no support for negative value */
- tuple_val = strtoul(value, NULL, 0);
- if ((errno == ERANGE && tuple_val == ULONG_MAX)
- || (errno != 0 && tuple_val == 0)) {
- SNDERR("error: tuple %s:strtoul fail\n", id);
+ ival = tplg_get_unsigned(n, &tuple_val, 0);
+ if (ival < 0) {
+ SNDERR("error: tuple %s: %s\n", id, snd_strerror(ival));
goto err;
}
@@ -654,7 +645,7 @@ static int parse_tuple_set(snd_config_t *cfg,
goto err;
}
- tuple->value = (unsigned int) tuple_val;
+ tuple->value = tuple_val;
tplg_dbg("\t\t%s = 0x%x\n", tuple->token, tuple->value);
break;
diff --git a/src/topology/parser.c b/src/topology/parser.c
index 667c8d45517b..f56ad97e42b9 100644
--- a/src/topology/parser.c
+++ b/src/topology/parser.c
@@ -55,6 +55,53 @@ int tplg_get_integer(snd_config_t *n, int *val, int base)
}
}
+/*
+ * Get unsigned integer value
+ */
+int tplg_get_unsigned(snd_config_t *n, unsigned *val, int base)
+{
+ const char *str;
+ long lval;
+ long long llval;
+ unsigned long uval;
+ int err;
+
+ switch (snd_config_get_type(n)) {
+ case SND_CONFIG_TYPE_INTEGER:
+ err = snd_config_get_integer(n, &lval);
+ if (err < 0)
+ return err;
+ if (lval < 0 || lval > UINT_MAX)
+ return -ERANGE;
+ *val = lval;
+ return err;
+ case SND_CONFIG_TYPE_INTEGER64:
+ err = snd_config_get_integer64(n, &llval);
+ if (err < 0)
+ return err;
+ if (llval < 0 || llval > UINT_MAX)
+ return -ERANGE;
+ *val = llval;
+ return err;
+ case SND_CONFIG_TYPE_STRING:
+ err = snd_config_get_string(n, &str);
+ if (err < 0)
+ return err;
+ errno = 0;
+ uval = strtoul(str, NULL, base);
+ if (errno == ERANGE && uval == ULONG_MAX)
+ return -ERANGE;
+ if (errno && uval == 0)
+ return -EINVAL;
+ if (uval > UINT_MAX)
+ return -ERANGE;
+ *val = uval;
+ return 0;
+ default:
+ return -EINVAL;
+ }
+}
+
/*
* Parse compound
*/
diff --git a/src/topology/pcm.c b/src/topology/pcm.c
index 6364e24f3c43..9b87549cabbd 100644
--- a/src/topology/pcm.c
+++ b/src/topology/pcm.c
@@ -606,8 +606,7 @@ static int tplg_parse_fe_dai(snd_tplg_t *tplg ATTRIBUTE_UNUSED,
struct snd_soc_tplg_pcm *pcm = elem->pcm;
snd_config_iterator_t i, next;
snd_config_t *n;
- const char *id, *value = NULL;
- unsigned long int id_val;
+ const char *id;
snd_config_get_id(cfg, &id);
tplg_dbg("\t\tFE DAI %s:\n", id);
@@ -622,19 +621,11 @@ static int tplg_parse_fe_dai(snd_tplg_t *tplg ATTRIBUTE_UNUSED,
continue;
if (strcmp(id, "id") == 0) {
- if (snd_config_get_string(n, &value) < 0)
- continue;
- errno = 0;
- /* no support for negative value */
- id_val = strtoul(value, NULL, 0);
- if ((errno == ERANGE && id_val == ULONG_MAX)
- || (errno != 0 && id_val == 0)
- || id_val > UINT_MAX) {
+ if (tplg_get_unsigned(n, &pcm->dai_id, 0)) {
SNDERR("error: invalid fe dai ID\n");
return -EINVAL;
}
- pcm->dai_id = (int) id_val;
tplg_dbg("\t\t\tindex: %d\n", pcm->dai_id);
}
}
diff --git a/src/topology/tplg_local.h b/src/topology/tplg_local.h
index 991e0b4121bd..e16c78d49709 100644
--- a/src/topology/tplg_local.h
+++ b/src/topology/tplg_local.h
@@ -281,6 +281,7 @@ struct tplg_elem* tplg_elem_new_common(snd_tplg_t *tplg,
snd_config_t *cfg, const char *name, enum snd_tplg_type type);
int tplg_get_integer(snd_config_t *n, int *val, int base);
+int tplg_get_unsigned(snd_config_t *n, unsigned *val, int base);
int tplg_parse_channel(snd_tplg_t *tplg ATTRIBUTE_UNUSED,
snd_config_t *cfg, void *private);
--
2.16.4