From 7f3ad37fd7e9327542be7f467ad337dd7398e2b7 Mon Sep 17 00:00:00 2001 From: Jaroslav Kysela Date: Sun, 22 Oct 2017 15:02:19 +0200 Subject: [PATCH] topology: fix coverity issues --- src/topology/ctl.c | 6 +++--- src/topology/dapm.c | 7 ++++++- src/topology/data.c | 7 +++---- src/topology/elem.c | 4 +++- 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/topology/ctl.c b/src/topology/ctl.c index e73d9eb7..9dd88db6 100644 --- a/src/topology/ctl.c +++ b/src/topology/ctl.c @@ -130,7 +130,7 @@ static int tplg_build_mixer_control(snd_tplg_t *tplg, list_for_each(pos, base) { ref = list_entry(pos, struct tplg_ref, list); - if (ref->id == NULL || ref->elem) + if (ref->elem) continue; if (ref->type == SND_TPLG_TYPE_TLV) { @@ -180,7 +180,7 @@ static int tplg_build_enum_control(snd_tplg_t *tplg, list_for_each(pos, base) { ref = list_entry(pos, struct tplg_ref, list); - if (ref->id == NULL || ref->elem) + if (ref->elem) continue; if (ref->type == SND_TPLG_TYPE_TEXT) { @@ -216,7 +216,7 @@ static int tplg_build_bytes_control(snd_tplg_t *tplg, struct tplg_elem *elem) list_for_each(pos, base) { ref = list_entry(pos, struct tplg_ref, list); - if (ref->id == NULL || ref->elem) + if (ref->elem) continue; if (ref->type == SND_TPLG_TYPE_DATA) { diff --git a/src/topology/dapm.c b/src/topology/dapm.c index 0ddbf965..e5d473a8 100644 --- a/src/topology/dapm.c +++ b/src/topology/dapm.c @@ -428,7 +428,7 @@ int tplg_parse_dapm_graph(snd_tplg_t *tplg, snd_config_t *cfg, snd_config_t *n; int err; const char *graph_id, *val = NULL; - int index; + int index = -1; if (snd_config_get_type(cfg) != SND_CONFIG_TYPE_COMPOUND) { SNDERR("error: compound is expected for dapm graph definition\n"); @@ -452,6 +452,11 @@ int tplg_parse_dapm_graph(snd_tplg_t *tplg, snd_config_t *cfg, } if (strcmp(id, "lines") == 0) { + if (index < 0) { + SNDERR("error: failed to parse dapm graph %s, missing index\n", + graph_id); + return -EINVAL; + } err = tplg_parse_routes(tplg, n, index); if (err < 0) { SNDERR("error: failed to parse dapm graph %s\n", diff --git a/src/topology/data.c b/src/topology/data.c index f96ff9bb..6b7c3f6c 100644 --- a/src/topology/data.c +++ b/src/topology/data.c @@ -132,7 +132,6 @@ err: static void dump_priv_data(struct tplg_elem *elem) { struct snd_soc_tplg_private *priv = elem->data; - unsigned char *p = (unsigned char *)priv->data; unsigned int i, j = 0; tplg_dbg(" elem size = %d, priv data size = %d\n", @@ -366,7 +365,7 @@ static struct tplg_elem *get_tokens(snd_tplg_t *tplg, struct tplg_elem *elem) ref = list_entry(pos, struct tplg_ref, list); - if (!ref->id || ref->type != SND_TPLG_TYPE_TOKEN) + if (ref->type != SND_TPLG_TYPE_TOKEN) continue; if (!ref->elem) { @@ -390,7 +389,7 @@ static bool has_tuples(struct tplg_elem *elem) list_for_each(pos, base) { ref = list_entry(pos, struct tplg_ref, list); - if (ref->id && ref->type == SND_TPLG_TYPE_TUPLE) + if (ref->type == SND_TPLG_TYPE_TUPLE) return true; } @@ -504,7 +503,7 @@ static int build_tuples(snd_tplg_t *tplg, struct tplg_elem *elem) ref = list_entry(pos, struct tplg_ref, list); - if (!ref->id || ref->type != SND_TPLG_TYPE_TUPLE) + if (ref->type != SND_TPLG_TYPE_TUPLE) continue; tplg_dbg("tuples '%s' used by data '%s'\n", ref->id, elem->id); diff --git a/src/topology/elem.c b/src/topology/elem.c index 9a7c7b75..16ad4423 100644 --- a/src/topology/elem.c +++ b/src/topology/elem.c @@ -178,8 +178,10 @@ struct tplg_elem* tplg_elem_new_common(snd_tplg_t *tplg, if (snd_config_get_id(n, &id)) continue; if (strcmp(id, "index") == 0) { - if (snd_config_get_string(n, &val) < 0) + if (snd_config_get_string(n, &val) < 0) { + free(elem); return NULL; + } elem->index = atoi(val); } } -- 2.47.1