]> git.alsa-project.org Git - alsa-lib.git/commitdiff
topology: fix coverity issues
authorJaroslav Kysela <perex@perex.cz>
Sun, 22 Oct 2017 13:02:19 +0000 (15:02 +0200)
committerJaroslav Kysela <perex@perex.cz>
Sun, 22 Oct 2017 13:02:19 +0000 (15:02 +0200)
src/topology/ctl.c
src/topology/dapm.c
src/topology/data.c
src/topology/elem.c

index e73d9eb71f2644cb87001041a0227217c205a3d8..9dd88db6b0defa5263e6c802c0d46090cb6c9625 100644 (file)
@@ -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) {
index 0ddbf965207a0daab9b61de32c26e426e4f41c70..e5d473a89745203219b65a1a1447c6079672f3e2 100644 (file)
@@ -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",
index f96ff9bb8eda3b91a614b9421f11c92d336e9521..6b7c3f6ce8f8257d315b41261ffc39e08b4ac427 100644 (file)
@@ -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);
index 9a7c7b75f9b347e7f0fa111caace3ce68d9b23cf..16ad44235dca9aea8f74202121b5a3fb733bd971 100644 (file)
@@ -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);
                        }
                }