Hello community,

here is the log from the commit of package alsa for openSUSE:Factory checked in 
at 2020-01-24 13:05:33
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Comparing /work/SRC/openSUSE:Factory/alsa (Old)
 and      /work/SRC/openSUSE:Factory/.alsa.new.26092 (New)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Package is "alsa"

Fri Jan 24 13:05:33 2020 rev:196 rq:766334 version:1.2.1.2

Changes:
--------
--- /work/SRC/openSUSE:Factory/alsa/alsa.changes        2020-01-02 
14:40:18.252887202 +0100
+++ /work/SRC/openSUSE:Factory/.alsa.new.26092/alsa.changes     2020-01-24 
13:08:14.125362534 +0100
@@ -1,0 +2,40 @@
+Tue Jan 21 15:49:49 CET 2020 - [email protected]
+
+- 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
+  0059-Quote-strings-containing-or-when-saving-an-alsa-conf.patch
+  0060-ucm-fix-the-configuration-directory-longname-for-ucm.patch
+  0061-ucm-split-conf_file_name-and-conf_dir_name.patch
+  0062-ucm-remove-MAX_FILE-definition-and-use-correct-PATH_.patch
+  0063-topology-remove-MAX_FILE-definition-and-use-correct-.patch
+- Remove INSTALL document, add NOTES instead
+
+-------------------------------------------------------------------

New:
----
  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
  0059-Quote-strings-containing-or-when-saving-an-alsa-conf.patch
  0060-ucm-fix-the-configuration-directory-longname-for-ucm.patch
  0061-ucm-split-conf_file_name-and-conf_dir_name.patch
  0062-ucm-remove-MAX_FILE-definition-and-use-correct-PATH_.patch
  0063-topology-remove-MAX_FILE-definition-and-use-correct-.patch

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Other differences:
------------------
++++++ alsa.spec ++++++
--- /var/tmp/diff_new_pack.Gim5RP/_old  2020-01-24 13:08:17.037363704 +0100
+++ /var/tmp/diff_new_pack.Gim5RP/_new  2020-01-24 13:08:17.037363704 +0100
@@ -1,7 +1,7 @@
 #
 # spec file for package alsa
 #
-# Copyright (c) 2019 SUSE LINUX GmbH, Nuernberg, Germany.
+# Copyright (c) 2020 SUSE LINUX GmbH, Nuernberg, Germany.
 #
 # All modifications and additions to the file contributed by third parties
 # remain the property of their copyright owners, unless otherwise agreed
@@ -79,6 +79,38 @@
 Patch29:        0029-Fix-alsa-sound-.h-for-external-programs.patch
 Patch30:        0030-type_compat-Add-missing-__s64-and-__u64-definitions-.patch
 Patch31:        0031-uapi-Move-typedefs-from-uapi-to-sound.patch
+Patch32:        0032-Update-the-attributes.m4-macro-file-from-xine.patch
+Patch33:        0033-topology-avoid-to-use-the-atoi-directly-when-expecte.patch
+Patch34:        0034-topology-use-snd_config_get_bool-instead-own-impleme.patch
+Patch35:        0035-topology-fix-tplg_get_integer-handle-errno-ERANGE.patch
+Patch36:        0036-topology-add-tplg_get_unsigned-function.patch
+Patch37:        0037-topology-convert-builder-to-use-the-mallocated-memor.patch
+Patch38:        0038-topology-add-binary-output-from-the-builder.patch
+Patch39:        0039-topology-parser-recode-tplg_parse_config.patch
+Patch40:        0040-topology-add-snd_tplg_load-remove-snd_tplg_build_bin.patch
+Patch41:        0041-topology-move-the-topology-element-table-from-builde.patch
+Patch42:        0042-topology-add-parser-to-the-tplg_table.patch
+Patch43:        0043-topology-add-snd_tplg_save.patch
+Patch44:        0044-topology-add-snd_tplg_create-with-flags.patch
+Patch45:        0045-topology-add-snd_tplg_version-function.patch
+Patch46:        0046-topology-cleanup-the-SNDERR-calls.patch
+Patch47:        0047-topology-dapm-fix-the-SNDERR-Undefined.patch
+Patch48:        0048-topology-fix-the-unitialized-tuples.patch
+Patch49:        0049-topology-implement-shorter-hexa-uuid-00-00-parser.patch
+Patch50:        0050-topology-fix-the-TPLG_DEBUG-compilation.patch
+Patch51:        0051-topology-fix-the-ops-parser-accept-integer-hexa-valu.patch
+Patch52:        0052-topology-fix-the-wrong-memory-access-object-realloc.patch
+Patch53:        0053-topology-implement-snd_tplg_decode.patch
+Patch54:        0054-topology-move-the-elem-list-delete-to-tplg_elem_free.patch
+Patch55:        0055-topology-unify-the-log-mechanism.patch
+Patch56:        0056-topology-tplg_dbg-cleanups.patch
+Patch57:        0057-topology-cosmetic-changes-functions.patch
+Patch58:        0058-mixer-Fix-memory-leak-for-more-than-16-file-descript.patch
+Patch59:        0059-Quote-strings-containing-or-when-saving-an-alsa-conf.patch
+Patch60:        0060-ucm-fix-the-configuration-directory-longname-for-ucm.patch
+Patch61:        0061-ucm-split-conf_file_name-and-conf_dir_name.patch
+Patch62:        0062-ucm-remove-MAX_FILE-definition-and-use-correct-PATH_.patch
+Patch63:        0063-topology-remove-MAX_FILE-definition-and-use-correct-.patch
 # rest suse fixes
 Patch101:       alsa-lib-ignore-non-accessible-ALSA_CONFIG_PATH.patch
 BuildRequires:  doxygen
@@ -194,6 +226,38 @@
 %patch29 -p1
 %patch30 -p1
 %patch31 -p1
+%patch32 -p1
+%patch33 -p1
+%patch34 -p1
+%patch35 -p1
+%patch36 -p1
+%patch37 -p1
+%patch38 -p1
+%patch39 -p1
+%patch40 -p1
+%patch41 -p1
+%patch42 -p1
+%patch43 -p1
+%patch44 -p1
+%patch45 -p1
+%patch46 -p1
+%patch47 -p1
+%patch48 -p1
+%patch49 -p1
+%patch50 -p1
+%patch51 -p1
+%patch52 -p1
+%patch53 -p1
+%patch54 -p1
+%patch55 -p1
+%patch56 -p1
+%patch57 -p1
+%patch58 -p1
+%patch59 -p1
+%patch60 -p1
+%patch61 -p1
+%patch62 -p1
+%patch63 -p1
 %patch101 -p1
 
 %build
@@ -279,7 +343,7 @@
 cp COPYING %{buildroot}%{_docdir}/%{name}
 %endif
 mkdir -p %{buildroot}%{_docdir}/%{name}/alsa-lib
-cp ChangeLog INSTALL TODO MEMORY-LEAK %{buildroot}%{_docdir}/%{name}/alsa-lib
+cp ChangeLog TODO MEMORY-LEAK NOTES %{buildroot}%{_docdir}/%{name}/alsa-lib
 cp doc/asoundrc.txt %{buildroot}%{_docdir}/%{name}/alsa-lib
 
 %post

++++++ 0032-Update-the-attributes.m4-macro-file-from-xine.patch ++++++
>From 9e2bbccfcc8069a676519149a280f20c1e05f0ac Mon Sep 17 00:00:00 2001
From: David Ward <[email protected]>
Date: Fri, 3 Jan 2020 13:05:51 -0500
Subject: [PATCH 32/63] Update the attributes.m4 macro file from xine
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This file was imported from the xine project. Update it to the current
revision, which resolves the "no AC_LANG_SOURCE call detected in body"
warnings with Autoconf 2.68 or later.

Cc: Diego Pettenò <[email protected]>
Signed-off-by: David Ward <[email protected]>
Signed-off-by: Jaroslav Kysela <[email protected]>
---
 m4/attributes.m4 | 33 ++++++++++++++++++++-------------
 1 file changed, 20 insertions(+), 13 deletions(-)

diff --git a/m4/attributes.m4 b/m4/attributes.m4
index e86456a468e5..3d9c256a09a2 100644
--- a/m4/attributes.m4
+++ b/m4/attributes.m4
@@ -1,6 +1,6 @@
 dnl Macros to check the presence of generic (non-typed) symbols.
-dnl Copyright (c) 2006-2007 Diego Pettenò <[email protected]>
-dnl Copyright (c) 2006-2007 xine project
+dnl Copyright (c) 2006-2008 Diego Pettenò <[email protected]>
+dnl Copyright (c) 2006-2008 xine project
 dnl
 dnl This program is free software; you can redistribute it and/or modify
 dnl it under the terms of the GNU General Public License as published by
@@ -25,7 +25,7 @@ dnl License when using or distributing such scripts, even 
though portions
 dnl of the text of the Macro appear in them. The GNU General Public
 dnl License (GPL) does govern all other use of the material that
 dnl constitutes the Autoconf Macro.
-dnl 
+dnl
 dnl This special exception to the GPL applies to versions of the
 dnl Autoconf Macro released by this project. When you make and
 dnl distribute a modified version of the Autoconf Macro, you may extend
@@ -39,7 +39,7 @@ AC_DEFUN([CC_CHECK_CFLAGS_SILENT], [
   AC_CACHE_VAL(AS_TR_SH([cc_cv_cflags_$1]),
     [ac_save_CFLAGS="$CFLAGS"
      CFLAGS="$CFLAGS $1"
-     AC_COMPILE_IFELSE([int a;],
+     AC_COMPILE_IFELSE([AC_LANG_SOURCE([int a;])],
        [eval "AS_TR_SH([cc_cv_cflags_$1])='yes'"],
        [eval "AS_TR_SH([cc_cv_cflags_$1])='no'"])
      CFLAGS="$ac_save_CFLAGS"
@@ -71,7 +71,7 @@ AC_DEFUN([CC_CHECK_CFLAG_APPEND], [
   )
 
   AS_IF([eval test x$]AS_TR_SH([cc_cv_cflags_$1])[ = xyes],
-    [CFLAGS="$CFLAGS $1"; $2], [$3])
+    [CFLAGS="$CFLAGS $1"; DEBUG_CFLAGS="$DEBUG_CFLAGS $1"; $2], [$3])
 ])
 
 dnl CC_CHECK_CFLAGS_APPEND([FLAG1 FLAG2], [action-if-found], [action-if-not])
@@ -89,7 +89,7 @@ AC_DEFUN([CC_CHECK_LDFLAGS], [
     AS_TR_SH([cc_cv_ldflags_$1]),
     [ac_save_LDFLAGS="$LDFLAGS"
      LDFLAGS="$LDFLAGS $1"
-     AC_LINK_IFELSE([int main() { return 1; }],
+     AC_LINK_IFELSE([AC_LANG_SOURCE([int main() { return 1; }])],
        [eval "AS_TR_SH([cc_cv_ldflags_$1])='yes'"],
        [eval "AS_TR_SH([cc_cv_ldflags_$1])="])
      LDFLAGS="$ac_save_LDFLAGS"
@@ -109,14 +109,21 @@ AC_DEFUN([CC_NOUNDEFINED], [
      dnl FreeBSD (et al.) does not complete linking for shared objects when 
pthreads
      dnl are requested, as different implementations are present; to avoid 
problems
      dnl use -Wl,-z,defs only for those platform not behaving this way.
-     *-freebsd*) ;;
+     dnl
+     dnl MinGW platforms: for libraries required -no-undefined,
+     dnl use it only for libraries in mingw32-w64 
+
+     *-freebsd* | *-openbsd*) ;;
+     *-mingw*)
+        LDFLAGS_NOUNDEFINED="-no-undefined"
+        ;;
      *)
         dnl First of all check for the --no-undefined variant of GNU ld. This 
allows
         dnl for a much more readable commandline, so that people can 
understand what
         dnl it does without going to look for what the heck -z defs does.
-       for possible_flags in "-Wl,--no-undefined" "-Wl,-z,defs"; do
+       for possible_flags in "-Wl,--no-undefined" "-Wl,-z,defs"; do
           CC_CHECK_LDFLAGS([$possible_flags], 
[LDFLAGS_NOUNDEFINED="$possible_flags"])
-         break
+         if test "x$LDFLAGS_NOUNDEFINED" = "x"; then break; fi
         done
        ;;
   esac
@@ -147,7 +154,7 @@ AC_DEFUN([CC_CHECK_ATTRIBUTE], [
     AS_TR_SH([cc_cv_attribute_$1]),
     [ac_save_CFLAGS="$CFLAGS"
      CFLAGS="$CFLAGS $cc_cv_werror"
-     AC_COMPILE_IFELSE([$3],
+     AC_COMPILE_IFELSE([AC_LANG_SOURCE([$3])],
        [eval "AS_TR_SH([cc_cv_attribute_$1])='yes'"],
        [eval "AS_TR_SH([cc_cv_attribute_$1])='no'"])
      CFLAGS="$ac_save_CFLAGS"
@@ -257,7 +264,7 @@ AC_DEFUN([CC_FLAG_VISIBILITY], [
        cc_cv_flag_visibility='yes',
        cc_cv_flag_visibility='no')
      CFLAGS="$cc_flag_visibility_save_CFLAGS"])
-  
+
   AS_IF([test "x$cc_cv_flag_visibility" = "xyes"],
     [AC_DEFINE([SUPPORT_FLAG_VISIBILITY], 1,
        [Define this if the compiler supports the -fvisibility flag])
@@ -295,11 +302,11 @@ AC_DEFUN([CC_ATTRIBUTE_ALIGNED], [
     [ac_save_CFLAGS="$CFLAGS"
      CFLAGS="$CFLAGS $cc_cv_werror"
      for cc_attribute_align_try in 64 32 16 8 4 2; do
-        AC_COMPILE_IFELSE([
+        AC_COMPILE_IFELSE([AC_LANG_SOURCE([
           int main() {
             static char c __attribute__ ((aligned($cc_attribute_align_try))) = 
0;
             return c;
-          }], [cc_cv_attribute_aligned=$cc_attribute_align_try; break])
+          }])], [cc_cv_attribute_aligned=$cc_attribute_align_try; break])
      done
      CFLAGS="$ac_save_CFLAGS"
   ])
-- 
2.16.4

++++++ 0033-topology-avoid-to-use-the-atoi-directly-when-expecte.patch ++++++
++++ 763 lines (skipped)

++++++ 0034-topology-use-snd_config_get_bool-instead-own-impleme.patch ++++++
>From 5925a6d870331c631f85ed4e18a8c5e6459b3c36 Mon Sep 17 00:00:00 2001
From: Jaroslav Kysela <[email protected]>
Date: Sat, 14 Dec 2019 13:50:04 +0100
Subject: [PATCH 34/63] topology: use snd_config_get_bool() instead own
 implementation

Signed-off-by: Jaroslav Kysela <[email protected]>
---
 src/topology/ctl.c  |  9 +++------
 src/topology/dapm.c |  9 ++++-----
 src/topology/data.c | 15 ++++++++++++---
 src/topology/pcm.c  | 29 +++++++++++++++--------------
 4 files changed, 34 insertions(+), 28 deletions(-)

diff --git a/src/topology/ctl.c b/src/topology/ctl.c
index e1896f46c576..9190efefb575 100644
--- a/src/topology/ctl.c
+++ b/src/topology/ctl.c
@@ -657,13 +657,10 @@ int tplg_parse_control_mixer(snd_tplg_t *tplg,
                }
 
                if (strcmp(id, "invert") == 0) {
-                       if (snd_config_get_string(n, &val) < 0)
+                       ival = snd_config_get_bool(n);
+                       if (ival < 0)
                                return -EINVAL;
-
-                       if (strcmp(val, "true") == 0)
-                               mc->invert = 1;
-                       else if (strcmp(val, "false") == 0)
-                               mc->invert = 0;
+                       mc->invert = ival;
 
                        tplg_dbg("\t%s: %d\n", id, mc->invert);
                        continue;
diff --git a/src/topology/dapm.c b/src/topology/dapm.c
index c6fd793d0d72..ad7092107896 100644
--- a/src/topology/dapm.c
+++ b/src/topology/dapm.c
@@ -479,8 +479,7 @@ int tplg_parse_dapm_widget(snd_tplg_t *tplg,
        snd_config_iterator_t i, next;
        snd_config_t *n;
        const char *id, *val = NULL;
-       int widget_type, err;
-       int ival;
+       int widget_type, err, ival;
 
        elem = tplg_elem_new_common(tplg, cfg, NULL, SND_TPLG_TYPE_DAPM_WIDGET);
        if (!elem)
@@ -531,11 +530,11 @@ int tplg_parse_dapm_widget(snd_tplg_t *tplg,
                }
 
                if (strcmp(id, "no_pm") == 0) {
-                       if (snd_config_get_string(n, &val) < 0)
+                       ival = snd_config_get_bool(n);
+                       if (ival < 0)
                                return -EINVAL;
 
-                       if (strcmp(val, "true") == 0)
-                               widget->reg = -1;
+                       widget->reg = ival ? -1 : 0;
 
                        tplg_dbg("\t%s: %s\n", id, val);
                        continue;
diff --git a/src/topology/data.c b/src/topology/data.c
index 0edfe54f3383..6b1337b39bad 100644
--- a/src/topology/data.c
+++ b/src/topology/data.c
@@ -557,6 +557,7 @@ static int parse_tuple_set(snd_config_t *cfg,
        unsigned int type, num_tuples = 0;
        struct tplg_tuple *tuple;
        unsigned long int tuple_val;
+       int ival;
 
        snd_config_get_id(cfg, &id);
 
@@ -607,25 +608,33 @@ static int parse_tuple_set(snd_config_t *cfg,
 
                switch (type) {
                case SND_SOC_TPLG_TUPLE_TYPE_UUID:
+                       if (snd_config_get_string(n, &value) < 0)
+                               continue;
                        if (get_uuid(value, tuple->uuid) < 0)
                                goto err;
                        break;
 
                case SND_SOC_TPLG_TUPLE_TYPE_STRING:
+                       if (snd_config_get_string(n, &value) < 0)
+                               continue;
                        snd_strlcpy(tuple->string, value,
                                SNDRV_CTL_ELEM_ID_NAME_MAXLEN);
                        tplg_dbg("\t\t%s = %s\n", tuple->token, tuple->string);
                        break;
 
                case SND_SOC_TPLG_TUPLE_TYPE_BOOL:
-                       if (strcmp(value, "true") == 0)
-                               tuple->value = 1;
+                       ival = snd_config_get_bool(n);
+                       if (ival < 0)
+                               continue;
+                       tuple->value = ival;
                        tplg_dbg("\t\t%s = %d\n", tuple->token, tuple->value);
                        break;
 
                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);
@@ -1012,7 +1021,7 @@ int tplg_parse_data(snd_tplg_t *tplg, snd_config_t *cfg,
 {
        snd_config_iterator_t i, next;
        snd_config_t *n;
-       const char *id, *val = NULL;
+       const char *id;
        int err = 0, ival;
        struct tplg_elem *elem;
 
diff --git a/src/topology/pcm.c b/src/topology/pcm.c
index d6c52b4752ee..6364e24f3c43 100644
--- a/src/topology/pcm.c
+++ b/src/topology/pcm.c
@@ -669,8 +669,8 @@ int tplg_parse_pcm(snd_tplg_t *tplg, snd_config_t *cfg,
        struct tplg_elem *elem;
        snd_config_iterator_t i, next;
        snd_config_t *n;
-       const char *id, *val = NULL;
-       int err;
+       const char *id;
+       int err, ival;
 
        elem = tplg_elem_new_common(tplg, cfg, NULL, SND_TPLG_TYPE_PCM);
        if (!elem)
@@ -709,11 +709,11 @@ int tplg_parse_pcm(snd_tplg_t *tplg, snd_config_t *cfg,
                }
 
                if (strcmp(id, "compress") == 0) {
-                       if (snd_config_get_string(n, &val) < 0)
+                       ival = snd_config_get_bool(n);
+                       if (ival < 0)
                                return -EINVAL;
 
-                       if (strcmp(val, "true") == 0)
-                               pcm->compress = 1;
+                       pcm->compress = ival;
 
                        tplg_dbg("\t%s: %s\n", id, val);
                        continue;
@@ -1107,7 +1107,7 @@ int tplg_parse_hw_config(snd_tplg_t *tplg, snd_config_t 
*cfg,
        snd_config_iterator_t i, next;
        snd_config_t *n;
        const char *id, *val = NULL;
-       int ret;
+       int ret, ival;
 
        elem = tplg_elem_new_common(tplg, cfg, NULL, SND_TPLG_TYPE_HW_CONFIG);
        if (!elem)
@@ -1178,11 +1178,11 @@ int tplg_parse_hw_config(snd_tplg_t *tplg, snd_config_t 
*cfg,
 
                if (strcmp(id, "bclk_invert") == 0 ||
                    strcmp(id, "invert_bclk") == 0) {
-                       if (snd_config_get_string(n, &val) < 0)
+                       ival = snd_config_get_bool(n);
+                       if (ival < 0)
                                return -EINVAL;
 
-                       if (!strcmp(val, "true"))
-                               hw_cfg->invert_bclk = true;
+                       hw_cfg->invert_bclk = ival;
                        continue;
                }
 
@@ -1209,11 +1209,11 @@ int tplg_parse_hw_config(snd_tplg_t *tplg, snd_config_t 
*cfg,
 
                if (strcmp(id, "fsync_invert") == 0 ||
                    strcmp(id, "invert_fsync") == 0) {
-                       if (snd_config_get_string(n, &val) < 0)
+                       ival = snd_config_get_bool(n);
+                       if (ival < 0)
                                return -EINVAL;
 
-                       if (!strcmp(val, "true"))
-                               hw_cfg->invert_fsync = true;
+                       hw_cfg->invert_fsync = ival;
                        continue;
                }
 
@@ -1254,10 +1254,11 @@ int tplg_parse_hw_config(snd_tplg_t *tplg, snd_config_t 
*cfg,
 
                if (strcmp(id, "pm_gate_clocks") == 0 ||
                    strcmp(id, "clock_gated") == 0) {
-                       if (snd_config_get_string(n, &val) < 0)
+                       ival = snd_config_get_bool(n);
+                       if (ival < 0)
                                return -EINVAL;
 
-                       if (!strcmp(val, "true"))
+                       if (ival)
                                hw_cfg->clock_gated =
                                        SND_SOC_TPLG_DAI_CLK_GATE_GATED;
                        else
-- 
2.16.4

++++++ 0035-topology-fix-tplg_get_integer-handle-errno-ERANGE.patch ++++++
>From 1047a5f3c0d39a3b0579db027f52d7facdf44077 Mon Sep 17 00:00:00 2001
From: Jaroslav Kysela <[email protected]>
Date: Sat, 14 Dec 2019 13:52:18 +0100
Subject: [PATCH 35/63] topology: fix tplg_get_integer() - handle errno ==
 ERANGE

Signed-off-by: Jaroslav Kysela <[email protected]>
---
 src/topology/parser.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/src/topology/parser.c b/src/topology/parser.c
index 7e657809307d..667c8d45517b 100644
--- a/src/topology/parser.c
+++ b/src/topology/parser.c
@@ -36,14 +36,19 @@ int tplg_get_integer(snd_config_t *n, int *val, int base)
                if (err < 0)
                        return err;
                if (lval < INT_MIN || lval > INT_MAX)
-                       return -EINVAL;
+                       return -ERANGE;
                *val = lval;
                return err;
        case SND_CONFIG_TYPE_STRING:
                err = snd_config_get_string(n, &str);
                if (err < 0)
                        return err;
+               errno = 0;
                *val = strtol(str, NULL, base);
+               if (errno == ERANGE)
+                       return -ERANGE;
+               if (errno && *val == 0)
+                       return -EINVAL;
                return 0;
        default:
                return -EINVAL;
-- 
2.16.4

++++++ 0036-topology-add-tplg_get_unsigned-function.patch ++++++
>From 14e43a11873d14ec6f16967c83629237ef44ac38 Mon Sep 17 00:00:00 2001
From: Jaroslav Kysela <[email protected]>
Date: Sat, 14 Dec 2019 14:05:49 +0100
Subject: [PATCH 36/63] topology: add tplg_get_unsigned() function

Signed-off-by: Jaroslav Kysela <[email protected]>
---
 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

++++++ 0037-topology-convert-builder-to-use-the-mallocated-memor.patch ++++++
>From 39fb37fef5bd3b3fa7a63e06a5f0a147197fddb9 Mon Sep 17 00:00:00 2001
From: Jaroslav Kysela <[email protected]>
Date: Sat, 14 Dec 2019 19:13:53 +0100
Subject: [PATCH 37/63] topology: convert builder to use the mallocated memory

Signed-off-by: Jaroslav Kysela <[email protected]>
---
 src/topology/builder.c    | 88 +++++++++++++++++++++++++++++++++++++----------
 src/topology/parser.c     | 74 ++++++++++++++++-----------------------
 src/topology/tplg_local.h |  5 +--
 3 files changed, 103 insertions(+), 64 deletions(-)

diff --git a/src/topology/builder.c b/src/topology/builder.c
index 1a22a453695a..40943b56e4aa 100644
--- a/src/topology/builder.c
+++ b/src/topology/builder.c
@@ -29,7 +29,7 @@ static void verbose(snd_tplg_t *tplg, const char *fmt, ...)
                return;
 
        va_start(va, fmt);
-       fprintf(stdout, "0x%6.6zx/%6.6zd - ", tplg->out_pos, tplg->out_pos);
+       fprintf(stdout, "0x%6.6zx/%6.6zd - ", tplg->bin_pos, tplg->bin_pos);
        vfprintf(stdout, fmt, va);
        va_end(va);
 }
@@ -37,18 +37,11 @@ static void verbose(snd_tplg_t *tplg, const char *fmt, ...)
 /* write a block, track the position */
 static ssize_t twrite(snd_tplg_t *tplg, void *data, size_t data_size)
 {
-       ssize_t r = write(tplg->out_fd, data, data_size);
-       if (r != (ssize_t)data_size) {
-               if (r < 0) {
-                       SNDERR("error: unable to write: %s", strerror(errno));
-                       return -errno;
-               }
-               tplg->out_pos += r;
-               SNDERR("error: unable to write (partial)");
+       if (tplg->bin_pos + data_size > tplg->bin_size)
                return -EIO;
-       }
-       tplg->out_pos += r;
-       return r;
+       memcpy(tplg->bin + tplg->bin_pos, data, data_size);
+       tplg->bin_pos += data_size;
+       return data_size;
 }
 
 /* write out block header to output file */
@@ -71,12 +64,12 @@ static ssize_t write_block_header(snd_tplg_t *tplg, 
unsigned int type,
        hdr.count = count;
 
        /* make sure file offset is aligned with the calculated HDR offset */
-       if (tplg->out_pos != tplg->next_hdr_pos) {
+       if (tplg->bin_pos != tplg->next_hdr_pos) {
                SNDERR("error: New header is at offset 0x%zx but file"
                        " offset 0x%zx is %s by %ld bytes\n",
-                       tplg->next_hdr_pos, tplg->out_pos,
-                       tplg->out_pos > tplg->next_hdr_pos ? "ahead" : "behind",
-                       labs(tplg->out_pos - tplg->next_hdr_pos));
+                       tplg->next_hdr_pos, tplg->bin_pos,
+                       tplg->bin_pos > tplg->next_hdr_pos ? "ahead" : "behind",
+                       labs(tplg->bin_pos - tplg->next_hdr_pos));
                return -EINVAL;
        }
 
@@ -163,6 +156,41 @@ static int write_elem_block(snd_tplg_t *tplg,
        return 0;
 }
 
+static size_t calc_manifest_size(snd_tplg_t *tplg)
+{
+       return sizeof(struct snd_soc_tplg_hdr) +
+              sizeof(tplg->manifest) +
+              tplg->manifest.priv.size;
+}
+
+static size_t calc_real_size(struct list_head *base)
+{
+       struct list_head *pos;
+       struct tplg_elem *elem, *elem_next;
+       size_t size = 0;
+
+       list_for_each(pos, base) {
+
+               elem = list_entry(pos, struct tplg_elem, list);
+
+               /* compound elems have already been copied to other elems */
+               if (elem->compound_elem)
+                       continue;
+
+               if (elem->size <= 0)
+                       continue;
+
+               size += elem->size;
+
+               elem_next = list_entry(pos->next, struct tplg_elem, list);
+
+               if ((pos->next == base) || (elem_next->index != elem->index))
+                       size += sizeof(struct snd_soc_tplg_hdr);
+       }
+
+       return size;
+}
+
 static size_t calc_block_size(struct list_head *base)
 {
        struct list_head *pos;
@@ -277,9 +305,27 @@ int tplg_write_data(snd_tplg_t *tplg)
        };
 
        ssize_t ret;
-       size_t size;
+       size_t total_size, size;
        unsigned int index;
 
+       /* calculate total size */
+       total_size = calc_manifest_size(tplg);
+       for (index = 0; index < ARRAY_SIZE(wtable); index++) {
+               wptr = &wtable[index];
+               size = calc_real_size(wptr->list);
+               total_size += size;
+       }
+
+       /* allocate new binary output */
+       free(tplg->bin);
+       tplg->bin = malloc(total_size);
+       tplg->bin_pos = 0;
+       tplg->bin_size = total_size;
+       if (tplg->bin == NULL) {
+               tplg->bin_size = 0;
+               return -ENOMEM;
+       }
+
        /* write manifest */
        ret = write_manifest_data(tplg);
        if (ret < 0) {
@@ -306,7 +352,13 @@ int tplg_write_data(snd_tplg_t *tplg)
                }
        }
 
-       verbose(tplg, "total size is 0x%zx/%zd\n", tplg->out_pos, 
tplg->out_pos);
+       verbose(tplg, "total size is 0x%zx/%zd\n", tplg->bin_pos, 
tplg->bin_pos);
+
+       if (total_size != tplg->bin_pos) {
+               SNDERR("total size mismatch (%zd != %zd)\n",
+                      total_size, tplg->bin_pos);
+               return -EINVAL;
+       }
 
        return 0;
 }
diff --git a/src/topology/parser.c b/src/topology/parser.c
index f56ad97e42b9..98a9f9e9deac 100644
--- a/src/topology/parser.c
+++ b/src/topology/parser.c
@@ -393,50 +393,29 @@ static int tplg_build_integ(snd_tplg_t *tplg)
        return err;
 }
 
-int snd_tplg_build_file(snd_tplg_t *tplg, const char *infile,
-       const char *outfile)
+int snd_tplg_build_file(snd_tplg_t *tplg,
+                       const char *infile,
+                       const char *outfile)
 {
        snd_config_t *cfg = NULL;
        int err = 0;
 
-       tplg->out_fd =
-               open(outfile, O_RDWR | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);
-       if (tplg->out_fd < 0) {
-               SNDERR("error: failed to open %s err %d\n",
-                       outfile, -errno);
-               return -errno;
-       }
-
        err = tplg_load_config(infile, &cfg);
        if (err < 0) {
                SNDERR("error: failed to load topology file %s\n",
                        infile);
-               goto out_close;
+               return err;
        }
 
        err = tplg_parse_config(tplg, cfg);
        if (err < 0) {
                SNDERR("error: failed to parse topology\n");
-               goto out;
-       }
-
-       err = tplg_build_integ(tplg);
-       if (err < 0) {
-               SNDERR("error: failed to check topology integrity\n");
-               goto out;
-       }
-
-       err = tplg_write_data(tplg);
-       if (err < 0) {
-               SNDERR("error: failed to write data %d\n", err);
-               goto out;
+               return err;
        }
 
-out:
        snd_config_delete(cfg);
-out_close:
-       close(tplg->out_fd);
-       return err;
+
+       return snd_tplg_build(tplg, outfile);
 }
 
 int snd_tplg_add_object(snd_tplg_t *tplg, snd_tplg_obj_template_t *t)
@@ -468,31 +447,38 @@ int snd_tplg_add_object(snd_tplg_t *tplg, 
snd_tplg_obj_template_t *t)
 
 int snd_tplg_build(snd_tplg_t *tplg, const char *outfile)
 {
-       int err;
-
-       tplg->out_fd =
-               open(outfile, O_RDWR | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);
-       if (tplg->out_fd < 0) {
-               SNDERR("error: failed to open %s err %d\n",
-                       outfile, -errno);
-               return -errno;
-       }
+       int fd, err;
+       ssize_t r;
 
        err = tplg_build_integ(tplg);
        if (err < 0) {
                SNDERR("error: failed to check topology integrity\n");
-               goto out;
+               return err;
        }
 
        err = tplg_write_data(tplg);
        if (err < 0) {
                SNDERR("error: failed to write data %d\n", err);
-               goto out;
+               return err;
        }
 
-out:
-       close(tplg->out_fd);
-       return err;
+       fd = open(outfile, O_RDWR | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);
+       if (fd < 0) {
+               SNDERR("error: failed to open %s err %d\n", outfile, -errno);
+               return -errno;
+       }
+       r = write(fd, tplg->bin, tplg->bin_size);
+       close(fd);
+       if (r < 0) {
+               err = -errno;
+               SNDERR("error: write error: %s\n", strerror(errno));
+               return err;
+       }
+       if ((size_t)r != tplg->bin_size) {
+               SNDERR("error: partial write (%zd != %zd)\n", r, 
tplg->bin_size);
+               return -EIO;
+       }
+       return 0;
 }
 
 int snd_tplg_set_manifest_data(snd_tplg_t *tplg, const void *data, int len)
@@ -571,8 +557,8 @@ snd_tplg_t *snd_tplg_new(void)
 
 void snd_tplg_free(snd_tplg_t *tplg)
 {
-       if (tplg->manifest_pdata)
-               free(tplg->manifest_pdata);
+       free(tplg->bin);
+       free(tplg->manifest_pdata);
 
        tplg_elem_free_list(&tplg->tlv_list);
        tplg_elem_free_list(&tplg->widget_list);
diff --git a/src/topology/tplg_local.h b/src/topology/tplg_local.h
index e16c78d49709..87e6c9a517de 100644
--- a/src/topology/tplg_local.h
+++ b/src/topology/tplg_local.h
@@ -60,8 +60,9 @@ typedef enum _snd_pcm_rates {
 
 struct snd_tplg {
        /* out file */
-       int out_fd;
-       size_t out_pos;
+       unsigned char *bin;
+       size_t bin_pos;
+       size_t bin_size;
 
        int verbose;
        unsigned int version;
-- 
2.16.4

++++++ 0038-topology-add-binary-output-from-the-builder.patch ++++++
>From bee8d4fcaa52d00950d035ec561513c2b9e7cac7 Mon Sep 17 00:00:00 2001
From: Jaroslav Kysela <[email protected]>
Date: Sat, 14 Dec 2019 19:20:02 +0100
Subject: [PATCH 38/63] topology: add binary output from the builder

- snd_tplg_build_bin()
- snd_tplg_build_bin_file()

Signed-off-by: Jaroslav Kysela <[email protected]>
---
 include/topology.h    | 22 +++++++++++++-
 src/topology/parser.c | 79 ++++++++++++++++++++++++++++++++++++++++++---------
 2 files changed, 87 insertions(+), 14 deletions(-)

diff --git a/include/topology.h b/include/topology.h
index 27da7308dd62..c9ef554a610f 100644
--- a/include/topology.h
+++ b/include/topology.h
@@ -791,7 +791,18 @@ void snd_tplg_free(snd_tplg_t *tplg);
  * \return Zero on success, otherwise a negative error code
  */
 int snd_tplg_build_file(snd_tplg_t *tplg, const char *infile,
-       const char *outfile);
+                       const char *outfile);
+
+/**
+ * \brief Parse and build topology text file into binary file.
+ * \param tplg Topology instance.
+ * \param infile Topology text input file to be parsed
+ * \param bin Binary topology output buffer (malloc).
+ * \param size Binary topology output buffer size in bytes.
+ * \return Zero on success, otherwise a negative error code
+ */
+int snd_tplg_build_bin_file(snd_tplg_t *tplg, const char *infile,
+                           void **bin, size_t *size);
 
 /**
  * \brief Enable verbose reporting of binary file output
@@ -1089,6 +1100,15 @@ int snd_tplg_add_object(snd_tplg_t *tplg, 
snd_tplg_obj_template_t *t);
  */
 int snd_tplg_build(snd_tplg_t *tplg, const char *outfile);
 
+/**
+ * \brief Build all registered topology data into memory.
+ * \param tplg Topology instance.
+ * \param bin Binary topology output buffer (malloc).
+ * \param size Binary topology output buffer size in bytes.
+ * \return Zero on success, otherwise a negative error code
+ */
+int snd_tplg_build_bin(snd_tplg_t *tplg, void **bin, size_t *size);
+
 /**
  * \brief Attach private data to topology manifest.
  * \param tplg Topology instance.
diff --git a/src/topology/parser.c b/src/topology/parser.c
index 98a9f9e9deac..861565b734ad 100644
--- a/src/topology/parser.c
+++ b/src/topology/parser.c
@@ -393,9 +393,7 @@ static int tplg_build_integ(snd_tplg_t *tplg)
        return err;
 }
 
-int snd_tplg_build_file(snd_tplg_t *tplg,
-                       const char *infile,
-                       const char *outfile)
+static int tplg_load(snd_tplg_t *tplg, const char *infile)
 {
        snd_config_t *cfg = NULL;
        int err = 0;
@@ -414,10 +412,53 @@ int snd_tplg_build_file(snd_tplg_t *tplg,
        }
 
        snd_config_delete(cfg);
+       return 0;
+}
+
+static int tplg_build(snd_tplg_t *tplg)
+{
+       int err;
+
+       err = tplg_build_integ(tplg);
+       if (err < 0) {
+               SNDERR("error: failed to check topology integrity\n");
+               return err;
+       }
+
+       err = tplg_write_data(tplg);
+       if (err < 0) {
+               SNDERR("error: failed to write data %d\n", err);
+               return err;
+       }
+       return 0;
+}
+
+int snd_tplg_build_file(snd_tplg_t *tplg,
+                       const char *infile,
+                       const char *outfile)
+{
+       int err;
+
+       err = tplg_load(tplg, infile);
+       if (err < 0)
+               return err;
 
        return snd_tplg_build(tplg, outfile);
 }
 
+int snd_tplg_build_bin_file(snd_tplg_t *tplg,
+                           const char *infile,
+                           void **bin, size_t *size)
+{
+       int err;
+
+       err = tplg_load(tplg, infile);
+       if (err < 0)
+               return err;
+
+       return snd_tplg_build_bin(tplg, bin, size);
+}
+
 int snd_tplg_add_object(snd_tplg_t *tplg, snd_tplg_obj_template_t *t)
 {
        switch (t->type) {
@@ -450,17 +491,9 @@ int snd_tplg_build(snd_tplg_t *tplg, const char *outfile)
        int fd, err;
        ssize_t r;
 
-       err = tplg_build_integ(tplg);
-       if (err < 0) {
-               SNDERR("error: failed to check topology integrity\n");
-               return err;
-       }
-
-       err = tplg_write_data(tplg);
-       if (err < 0) {
-               SNDERR("error: failed to write data %d\n", err);
+       err = tplg_build(tplg);
+       if (err < 0)
                return err;
-       }
 
        fd = open(outfile, O_RDWR | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);
        if (fd < 0) {
@@ -481,6 +514,26 @@ int snd_tplg_build(snd_tplg_t *tplg, const char *outfile)
        return 0;
 }
 
+int snd_tplg_build_bin(snd_tplg_t *tplg,
+                      void **bin, size_t *size)
+{
+       int err;
+
+       err = tplg_build(tplg);
+       if (err < 0)
+               return err;
+
+       err = tplg_build(tplg);
+       if (err < 0)
+               return err;
+
+       *bin = tplg->bin;
+       *size = tplg->bin_size;
+       tplg->bin = NULL;
+       tplg->bin_size = tplg->bin_pos = 0;
+       return 0;
+}
+
 int snd_tplg_set_manifest_data(snd_tplg_t *tplg, const void *data, int len)
 {
        if (len <= 0)
-- 
2.16.4

++++++ 0039-topology-parser-recode-tplg_parse_config.patch ++++++
>From 22b66731f3dc0eb5149a99ff547eeb84eaf8d54b Mon Sep 17 00:00:00 2001
From: Jaroslav Kysela <[email protected]>
Date: Sat, 14 Dec 2019 20:32:24 +0100
Subject: [PATCH 39/63] topology: parser - recode tplg_parse_config()

Signed-off-by: Jaroslav Kysela <[email protected]>
---
 src/topology/parser.c     | 225 +++++++++++++++++++---------------------------
 src/topology/tplg_local.h |  67 ++++----------
 2 files changed, 108 insertions(+), 184 deletions(-)

diff --git a/src/topology/parser.c b/src/topology/parser.c
index 861565b734ad..82af7cc518d8 100644
--- a/src/topology/parser.c
+++ b/src/topology/parser.c
@@ -142,9 +142,88 @@ int tplg_parse_compound(snd_tplg_t *tplg, snd_config_t 
*cfg,
 
 static int tplg_parse_config(snd_tplg_t *tplg, snd_config_t *cfg)
 {
+       static struct _parser {
+               const char *id;
+               int (*parser)(snd_tplg_t *tplg, snd_config_t *cfg, void *priv);
+       } *p, parsers[] = {
+               {
+                       .id = "SectionTLV",
+                       .parser = tplg_parse_tlv
+               },
+               {
+                       .id = "SectionControlMixer",
+                       .parser = tplg_parse_control_mixer
+               },
+               {
+                       .id = "SectionControlEnum",
+                       .parser = tplg_parse_control_enum
+               },
+               {
+                       .id = "SectionControlBytes",
+                       .parser = tplg_parse_control_bytes
+               },
+               {
+                       .id = "SectionWidget",
+                       .parser = tplg_parse_dapm_widget
+               },
+               {
+                       .id = "SectionPCMCapabilities",
+                       .parser = tplg_parse_stream_caps
+               },
+               {
+                       .id = "SectionPCM",
+                       .parser = tplg_parse_pcm
+               },
+               {
+                       .id = "SectionDAI",
+                       .parser = tplg_parse_dai
+               },
+               {
+                       .id = "SectionHWConfig",
+                       .parser = tplg_parse_hw_config
+               },
+               {
+                       .id = "SectionLink",
+                       .parser = tplg_parse_link
+               },
+               {
+                       .id = "SectionBE",
+                       .parser = tplg_parse_link
+               },
+               {
+                       .id = "SectionCC",
+                       .parser = tplg_parse_cc
+               },
+               {
+                       .id = "SectionGraph",
+                       .parser = tplg_parse_dapm_graph
+               },
+               {
+                       .id = "SectionText",
+                       .parser = tplg_parse_text
+               },
+               {
+                       .id = "SectionData",
+                       .parser = tplg_parse_data
+               },
+               {
+                       .id = "SectionVendorTokens",
+                       .parser = tplg_parse_tokens
+               },
+               {
+                       .id = "SectionVendorTuples",
+                       .parser = tplg_parse_tuples
+               },
+               {
+                       .id = "SectionManifest",
+                       .parser = tplg_parse_manifest_data
+               },
+       };
+       int (*parser)(snd_tplg_t *tplg, snd_config_t *cfg, void *priv);
        snd_config_iterator_t i, next;
        snd_config_t *n;
        const char *id;
+       unsigned int idx;
        int err;
 
        if (snd_config_get_type(cfg) != SND_CONFIG_TYPE_COMPOUND) {
@@ -159,145 +238,23 @@ static int tplg_parse_config(snd_tplg_t *tplg, 
snd_config_t *cfg)
                if (snd_config_get_id(n, &id) < 0)
                        continue;
 
-               if (strcmp(id, "SectionTLV") == 0) {
-                       err = tplg_parse_compound(tplg, n, tplg_parse_tlv,
-                               NULL);
-                       if (err < 0)
-                               return err;
-                       continue;
+               parser = NULL;
+               for (idx = 0; idx < ARRAY_SIZE(parsers); idx++) {
+                       p = &parsers[idx];
+                       if (strcmp(id, p->id) == 0) {
+                               parser = p->parser;
+                               break;
+                       }
                }
 
-               if (strcmp(id, "SectionControlMixer") == 0) {
-                       err = tplg_parse_compound(tplg, n,
-                               tplg_parse_control_mixer, NULL);
-                       if (err < 0)
-                               return err;
+               if (parser == NULL) {
+                       SNDERR("error: unknown section %s\n", id);
                        continue;
                }
 
-               if (strcmp(id, "SectionControlEnum") == 0) {
-                       err = tplg_parse_compound(tplg, n,
-                               tplg_parse_control_enum, NULL);
-                       if (err < 0)
-                               return err;
-                       continue;
-               }
-
-               if (strcmp(id, "SectionControlBytes") == 0) {
-                       err = tplg_parse_compound(tplg, n,
-                               tplg_parse_control_bytes, NULL);
-                       if (err < 0)
-                               return err;
-                       continue;
-               }
-
-               if (strcmp(id, "SectionWidget") == 0) {
-                       err = tplg_parse_compound(tplg, n,
-                               tplg_parse_dapm_widget, NULL);
-                       if (err < 0)
-                               return err;
-                       continue;
-               }
-
-               if (strcmp(id, "SectionPCMCapabilities") == 0) {
-                       err = tplg_parse_compound(tplg, n,
-                               tplg_parse_stream_caps, NULL);
-                       if (err < 0)
-                               return err;
-                       continue;
-               }
-
-               if (strcmp(id, "SectionPCM") == 0) {
-                       err = tplg_parse_compound(tplg, n,
-                               tplg_parse_pcm, NULL);
-                       if (err < 0)
-                               return err;
-                       continue;
-               }
-
-               if (strcmp(id, "SectionDAI") == 0) {
-                       err = tplg_parse_compound(tplg, n,
-                               tplg_parse_dai, NULL);
-                       if (err < 0)
-                               return err;
-                       continue;
-               }
-
-               if (strcmp(id, "SectionHWConfig") == 0) {
-                       err = tplg_parse_compound(tplg, n, tplg_parse_hw_config,
-                               NULL);
-                       if (err < 0)
-                               return err;
-                       continue;
-               }
-
-               if (strcmp(id, "SectionLink") == 0
-                       || strcmp(id, "SectionBE") == 0) {
-                       err = tplg_parse_compound(tplg, n, tplg_parse_link,
-                               NULL);
-                       if (err < 0)
-                               return err;
-                       continue;
-               }
-
-               if (strcmp(id, "SectionCC") == 0) {
-                       err = tplg_parse_compound(tplg, n, tplg_parse_cc,
-                               NULL);
-                       if (err < 0)
-                               return err;
-                       continue;
-               }
-
-               if (strcmp(id, "SectionGraph") == 0) {
-                       err = tplg_parse_compound(tplg, n,
-                               tplg_parse_dapm_graph, NULL);
-                       if (err < 0)
-                               return err;
-                       continue;
-               }
-
-               if (strcmp(id, "SectionText") == 0) {
-                       err = tplg_parse_compound(tplg, n, tplg_parse_text,
-                               NULL);
-                       if (err < 0)
-                               return err;
-                       continue;
-               }
-
-               if (strcmp(id, "SectionData") == 0) {
-                       err = tplg_parse_compound(tplg, n, tplg_parse_data,
-                               NULL);
-                       if (err < 0)
-                               return err;
-                       continue;
-               }
-
-               if (strcmp(id, "SectionVendorTokens") == 0) {
-                       err = tplg_parse_compound(tplg, n, tplg_parse_tokens,
-                               NULL);
-                       if (err < 0)
-                               return err;
-                       continue;
-               }
-
-               if (strcmp(id, "SectionVendorTuples") == 0) {
-                       err = tplg_parse_compound(tplg, n, tplg_parse_tuples,
-                               NULL);
-                       if (err < 0)
-                               return err;
-                       continue;
-               }
-
-               if (strcmp(id, "SectionManifest") == 0) {
-                       err = tplg_parse_compound(tplg, n,
-                                                 tplg_parse_manifest_data,
-                               NULL);
-                       if (err < 0)
-                               return err;
-                       continue;
-               }
-
-               SNDERR("error: unknown section %s\n", id);
+               err = tplg_parse_compound(tplg, n, parser, NULL);
+               if (err < 0)
+                       return err;
        }
        return 0;
 }
diff --git a/src/topology/tplg_local.h b/src/topology/tplg_local.h
index 87e6c9a517de..77a681897a85 100644
--- a/src/topology/tplg_local.h
+++ b/src/topology/tplg_local.h
@@ -202,59 +202,26 @@ int tplg_parse_compound(snd_tplg_t *tplg, snd_config_t 
*cfg,
 
 int tplg_write_data(snd_tplg_t *tplg);
 
-int tplg_parse_tlv(snd_tplg_t *tplg, snd_config_t *cfg,
-       void *private ATTRIBUTE_UNUSED);
-
-int tplg_parse_text(snd_tplg_t *tplg, snd_config_t *cfg,
-       void *private ATTRIBUTE_UNUSED);
-
-int tplg_parse_data(snd_tplg_t *tplg, snd_config_t *cfg,
-       void *private ATTRIBUTE_UNUSED);
-
-int tplg_parse_tokens(snd_tplg_t *tplg, snd_config_t *cfg,
-       void *private ATTRIBUTE_UNUSED);
-
-int tplg_parse_tuples(snd_tplg_t *tplg, snd_config_t *cfg,
-       void *private ATTRIBUTE_UNUSED);
+int tplg_parse_tlv(snd_tplg_t *tplg, snd_config_t *cfg, void *priv);
+int tplg_parse_text(snd_tplg_t *tplg, snd_config_t *cfg, void *priv);
+int tplg_parse_data(snd_tplg_t *tplg, snd_config_t *cfg, void *priv);
+int tplg_parse_tokens(snd_tplg_t *tplg, snd_config_t *cfg, void *priv);
+int tplg_parse_tuples(snd_tplg_t *tplg, snd_config_t *cfg, void *priv);
+int tplg_parse_manifest_data(snd_tplg_t *tplg, snd_config_t *cfg, void *priv);
+int tplg_parse_control_bytes(snd_tplg_t *tplg, snd_config_t *cfg, void *priv);
+int tplg_parse_control_enum(snd_tplg_t *tplg, snd_config_t *cfg, void *priv);
+int tplg_parse_control_mixer(snd_tplg_t *tplg, snd_config_t *cfg, void *priv);
+int tplg_parse_dapm_graph(snd_tplg_t *tplg, snd_config_t *cfg, void *priv);
+int tplg_parse_dapm_widget(snd_tplg_t *tplg, snd_config_t *cfg, void *priv);
+int tplg_parse_stream_caps(snd_tplg_t *tplg, snd_config_t *cfg, void *priv);
+int tplg_parse_pcm(snd_tplg_t *tplg, snd_config_t *cfg, void *priv);
+int tplg_parse_dai(snd_tplg_t *tplg, snd_config_t *cfg, void *priv);
+int tplg_parse_link(snd_tplg_t *tplg, snd_config_t *cfg, void *priv);
+int tplg_parse_cc(snd_tplg_t *tplg, snd_config_t *cfg, void *priv);
+int tplg_parse_hw_config(snd_tplg_t *tplg, snd_config_t *cfg, void *priv);
 
 void tplg_free_tuples(void *obj);
 
-int tplg_parse_manifest_data(snd_tplg_t *tplg, snd_config_t *cfg,
-       void *private ATTRIBUTE_UNUSED);
-
-int tplg_parse_control_bytes(snd_tplg_t *tplg,
-       snd_config_t *cfg, void *private ATTRIBUTE_UNUSED);
-
-int tplg_parse_control_enum(snd_tplg_t *tplg, snd_config_t *cfg,
-       void *private ATTRIBUTE_UNUSED);
-
-int tplg_parse_control_mixer(snd_tplg_t *tplg,
-       snd_config_t *cfg, void *private ATTRIBUTE_UNUSED);
-
-int tplg_parse_dapm_graph(snd_tplg_t *tplg, snd_config_t *cfg,
-       void *private ATTRIBUTE_UNUSED);
-
-int tplg_parse_dapm_widget(snd_tplg_t *tplg,
-       snd_config_t *cfg, void *private ATTRIBUTE_UNUSED);
-
-int tplg_parse_stream_caps(snd_tplg_t *tplg,
-       snd_config_t *cfg, void *private ATTRIBUTE_UNUSED);
-
-int tplg_parse_pcm(snd_tplg_t *tplg,
-       snd_config_t *cfg, void *private ATTRIBUTE_UNUSED);
-
-int tplg_parse_dai(snd_tplg_t *tplg, snd_config_t *cfg,
-                  void *private ATTRIBUTE_UNUSED);
-
-int tplg_parse_link(snd_tplg_t *tplg,
-       snd_config_t *cfg, void *private ATTRIBUTE_UNUSED);
-
-int tplg_parse_cc(snd_tplg_t *tplg,
-       snd_config_t *cfg, void *private ATTRIBUTE_UNUSED);
-
-int tplg_parse_hw_config(snd_tplg_t *tplg, snd_config_t *cfg,
-                        void *private ATTRIBUTE_UNUSED);
-
 int tplg_build_data(snd_tplg_t *tplg);
 int tplg_build_manifest_data(snd_tplg_t *tplg);
 int tplg_build_controls(snd_tplg_t *tplg);
-- 
2.16.4

++++++ 0040-topology-add-snd_tplg_load-remove-snd_tplg_build_bin.patch ++++++
>From d52eaba63dfe1d845663a4cd1bf676fafc43874a Mon Sep 17 00:00:00 2001
From: Jaroslav Kysela <[email protected]>
Date: Sun, 15 Dec 2019 16:03:29 +0100
Subject: [PATCH 40/63] topology: add snd_tplg_load() remove
 snd_tplg_build_bin_file()

Signed-off-by: Jaroslav Kysela <[email protected]>
---
 include/topology.h    | 16 ++++-----
 src/topology/parser.c | 96 ++++++++++++++++++---------------------------------
 2 files changed, 41 insertions(+), 71 deletions(-)

diff --git a/include/topology.h b/include/topology.h
index c9ef554a610f..c9f4ffea27de 100644
--- a/include/topology.h
+++ b/include/topology.h
@@ -784,25 +784,23 @@ snd_tplg_t *snd_tplg_new(void);
 void snd_tplg_free(snd_tplg_t *tplg);
 
 /**
- * \brief Parse and build topology text file into binary file.
+ * \brief Load topology from the text buffer.
  * \param tplg Topology instance.
- * \param infile Topology text input file to be parsed
- * \param outfile Binary topology output file.
+ * \param buf Text buffer.
+ * \param size Text buffer size in bytes.
  * \return Zero on success, otherwise a negative error code
  */
-int snd_tplg_build_file(snd_tplg_t *tplg, const char *infile,
-                       const char *outfile);
+int snd_tplg_load(snd_tplg_t *tplg, const char *buf, size_t size);
 
 /**
  * \brief Parse and build topology text file into binary file.
  * \param tplg Topology instance.
  * \param infile Topology text input file to be parsed
- * \param bin Binary topology output buffer (malloc).
- * \param size Binary topology output buffer size in bytes.
+ * \param outfile Binary topology output file.
  * \return Zero on success, otherwise a negative error code
  */
-int snd_tplg_build_bin_file(snd_tplg_t *tplg, const char *infile,
-                           void **bin, size_t *size);
+int snd_tplg_build_file(snd_tplg_t *tplg, const char *infile,
+                       const char *outfile);
 
 /**
  * \brief Enable verbose reporting of binary file output
diff --git a/src/topology/parser.c b/src/topology/parser.c
index 82af7cc518d8..ed864d3223c4 100644
--- a/src/topology/parser.c
+++ b/src/topology/parser.c
@@ -259,52 +259,30 @@ static int tplg_parse_config(snd_tplg_t *tplg, 
snd_config_t *cfg)
        return 0;
 }
 
-static int tplg_load_config(const char *file, snd_config_t **cfg)
+static int tplg_load_config(snd_tplg_t *tplg, snd_input_t *in)
 {
-       FILE *fp;
-       snd_input_t *in;
        snd_config_t *top;
        int ret;
 
-       fp = fopen(file, "r");
-       if (fp == NULL) {
-               SNDERR("error: could not open configuration file %s",
-                       file);
-               return -errno;
-       }
-
-       ret = snd_input_stdio_attach(&in, fp, 1);
-       if (ret < 0) {
-               fclose(fp);
-               SNDERR("error: could not attach stdio %s", file);
-               return ret;
-       }
        ret = snd_config_top(&top);
        if (ret < 0)
-               goto err;
+               return ret;
 
        ret = snd_config_load(top, in);
        if (ret < 0) {
-               SNDERR("error: could not load configuration file %s",
-                       file);
-               goto err_load;
+               SNDERR("error: could not load configuration");
+               snd_config_delete(top);
+               return ret;
        }
 
-       ret = snd_input_close(in);
+       ret = tplg_parse_config(tplg, top);
+       snd_config_delete(top);
        if (ret < 0) {
-               in = NULL;
-               goto err_load;
+               SNDERR("error: failed to parse topology");
+               return ret;
        }
 
-       *cfg = top;
        return 0;
-
-err_load:
-       snd_config_delete(top);
-err:
-       if (in)
-               snd_input_close(in);
-       return ret;
 }
 
 static int tplg_build_integ(snd_tplg_t *tplg)
@@ -350,26 +328,20 @@ static int tplg_build_integ(snd_tplg_t *tplg)
        return err;
 }
 
-static int tplg_load(snd_tplg_t *tplg, const char *infile)
+int snd_tplg_load(snd_tplg_t *tplg, const char *buf, size_t size)
 {
-       snd_config_t *cfg = NULL;
-       int err = 0;
-
-       err = tplg_load_config(infile, &cfg);
-       if (err < 0) {
-               SNDERR("error: failed to load topology file %s\n",
-                       infile);
-               return err;
-       }
+       snd_input_t *in;
+       int err;
 
-       err = tplg_parse_config(tplg, cfg);
+       err = snd_input_buffer_open(&in, buf, size);
        if (err < 0) {
-               SNDERR("error: failed to parse topology\n");
+               SNDERR("error: could not create input buffer");
                return err;
        }
 
-       snd_config_delete(cfg);
-       return 0;
+       err = tplg_load_config(tplg, in);
+       snd_input_close(in);
+       return err;
 }
 
 static int tplg_build(snd_tplg_t *tplg)
@@ -394,26 +366,30 @@ int snd_tplg_build_file(snd_tplg_t *tplg,
                        const char *infile,
                        const char *outfile)
 {
+       FILE *fp;
+       snd_input_t *in;
        int err;
 
-       err = tplg_load(tplg, infile);
-       if (err < 0)
-               return err;
-
-       return snd_tplg_build(tplg, outfile);
-}
+       fp = fopen(infile, "r");
+       if (fp == NULL) {
+               SNDERR("error: could not open configuration file %s",
+                      infile);
+               return -errno;
+       }
 
-int snd_tplg_build_bin_file(snd_tplg_t *tplg,
-                           const char *infile,
-                           void **bin, size_t *size)
-{
-       int err;
+       err = snd_input_stdio_attach(&in, fp, 1);
+       if (err < 0) {
+               fclose(fp);
+               SNDERR("error: could not attach stdio %s", infile);
+               return err;
+       }
 
-       err = tplg_load(tplg, infile);
+       err = tplg_load_config(tplg, in);
+       snd_input_close(in);
        if (err < 0)
                return err;
 
-       return snd_tplg_build_bin(tplg, bin, size);
+       return snd_tplg_build(tplg, outfile);
 }
 
 int snd_tplg_add_object(snd_tplg_t *tplg, snd_tplg_obj_template_t *t)
@@ -476,10 +452,6 @@ int snd_tplg_build_bin(snd_tplg_t *tplg,
 {
        int err;
 
-       err = tplg_build(tplg);
-       if (err < 0)
-               return err;
-
        err = tplg_build(tplg);
        if (err < 0)
                return err;
-- 
2.16.4

++++++ 0041-topology-move-the-topology-element-table-from-builde.patch ++++++
>From 4f076f5b69a873418ecb826a4198e4d95a3a2a6f Mon Sep 17 00:00:00 2001
From: Jaroslav Kysela <[email protected]>
Date: Sun, 15 Dec 2019 16:15:29 +0100
Subject: [PATCH 41/63] topology: move the topology element table from builder
 to elem

- use offsetof() for the lists
- add other info to describe the elements
- use the table in the element constructor

Signed-off-by: Jaroslav Kysela <[email protected]>
---
 src/topology/builder.c    |  98 ++++----------------
 src/topology/ctl.c        |   7 +-
 src/topology/elem.c       | 232 ++++++++++++++++++++++++++++++++--------------
 src/topology/tplg_local.h |  15 +++
 4 files changed, 199 insertions(+), 153 deletions(-)

diff --git a/src/topology/builder.c b/src/topology/builder.c
index 40943b56e4aa..cadb55830809 100644
--- a/src/topology/builder.c
+++ b/src/topology/builder.c
@@ -236,83 +236,20 @@ static ssize_t write_manifest_data(snd_tplg_t *tplg)
 
 int tplg_write_data(snd_tplg_t *tplg)
 {
-       struct wtable {
-               const char *name;
-               struct list_head *list;
-               int type;
-               int tsoc;
-       } *wptr, wtable[] = {
-               {
-                       .name = "control mixer",
-                       .list = &tplg->mixer_list,
-                       .type = SND_TPLG_TYPE_MIXER,
-                       .tsoc = SND_SOC_TPLG_TYPE_MIXER,
-               },
-               {
-                       .name = "control enum",
-                       .list = &tplg->enum_list,
-                       .type = SND_TPLG_TYPE_ENUM,
-                       .tsoc = SND_SOC_TPLG_TYPE_ENUM,
-               },
-               {
-                       .name = "control extended (bytes)",
-                       .list = &tplg->bytes_ext_list,
-                       .type = SND_TPLG_TYPE_BYTES,
-                       .tsoc = SND_SOC_TPLG_TYPE_BYTES,
-               },
-               {
-                       .name = "dapm widget",
-                       .list = &tplg->widget_list,
-                       .type = SND_TPLG_TYPE_DAPM_WIDGET,
-                       .tsoc = SND_SOC_TPLG_TYPE_DAPM_WIDGET,
-               },
-               {
-                       .name = "pcm",
-                       .list = &tplg->pcm_list,
-                       .type = SND_TPLG_TYPE_PCM,
-                       .tsoc = SND_SOC_TPLG_TYPE_PCM,
-               },
-               {
-                       .name = "physical dai",
-                       .list = &tplg->dai_list,
-                       .type = SND_TPLG_TYPE_DAI,
-                       .tsoc = SND_SOC_TPLG_TYPE_DAI,
-               },
-               {
-                       .name = "be",
-                       .list = &tplg->be_list,
-                       .type = SND_TPLG_TYPE_BE,
-                       .tsoc = SND_SOC_TPLG_TYPE_BACKEND_LINK,
-               },
-               {
-                       .name = "cc",
-                       .list = &tplg->cc_list,
-                       .type = SND_TPLG_TYPE_CC,
-                       .tsoc = SND_SOC_TPLG_TYPE_CODEC_LINK,
-               },
-               {
-                       .name = "route (dapm graph)",
-                       .list = &tplg->route_list,
-                       .type = SND_TPLG_TYPE_DAPM_GRAPH,
-                       .tsoc = SND_SOC_TPLG_TYPE_DAPM_GRAPH,
-               },
-               {
-                       .name = "private data",
-                       .list = &tplg->pdata_list,
-                       .type = SND_TPLG_TYPE_DATA,
-                       .tsoc = SND_SOC_TPLG_TYPE_PDATA,
-               },
-       };
-
+       struct tplg_table *tptr;
+       struct list_head *list;
        ssize_t ret;
        size_t total_size, size;
        unsigned int index;
 
        /* calculate total size */
        total_size = calc_manifest_size(tplg);
-       for (index = 0; index < ARRAY_SIZE(wtable); index++) {
-               wptr = &wtable[index];
-               size = calc_real_size(wptr->list);
+       for (index = 0; index < tplg_table_items; index++) {
+               tptr = &tplg_table[index];
+               if (!tptr->build)
+                       continue;
+               list = (struct list_head *)((void *)tplg + tptr->loff);
+               size = calc_real_size(list);
                total_size += size;
        }
 
@@ -334,20 +271,23 @@ int tplg_write_data(snd_tplg_t *tplg)
        }
 
        /* write all blocks */
-       for (index = 0; index < ARRAY_SIZE(wtable); index++) {
-               wptr = &wtable[index];
+       for (index = 0; index < tplg_table_items; index++) {
+               tptr = &tplg_table[index];
+               if (!tptr->build)
+                       continue;
+               list = (struct list_head *)((void *)tplg + tptr->loff);
                /* calculate the block size in bytes for all elems in this list 
*/
-               size = calc_block_size(wptr->list);
+               size = calc_block_size(list);
                if (size == 0)
                        continue;
                verbose(tplg, "block size for type %s (%d:%d) is 0x%zx/%zd\n",
-                                               wptr->name, wptr->type,
-                                               wptr->tsoc, size, size);
-               ret = write_elem_block(tplg, wptr->list, size,
-                                      wptr->tsoc, wptr->name);
+                                               tptr->name, tptr->type,
+                                               tptr->tsoc, size, size);
+               ret = write_elem_block(tplg, list, size,
+                                      tptr->tsoc, tptr->name);
                if (ret < 0) {
                        SNDERR("failed to write %s elements: %s\n",
-                                               wptr->name, snd_strerror(-ret));
+                                               tptr->name, snd_strerror(-ret));
                        return ret;
                }
        }
diff --git a/src/topology/ctl.c b/src/topology/ctl.c
index 9190efefb575..539329cd661f 100644
--- a/src/topology/ctl.c
+++ b/src/topology/ctl.c
@@ -284,18 +284,13 @@ static int tplg_parse_tlv_dbscale(snd_config_t *cfg, 
struct tplg_elem *elem)
 {
        snd_config_iterator_t i, next;
        snd_config_t *n;
-       struct snd_soc_tplg_ctl_tlv *tplg_tlv;
+       struct snd_soc_tplg_ctl_tlv *tplg_tlv = elem->tlv;
        struct snd_soc_tplg_tlv_dbscale *scale;
        const char *id = NULL;
        int val;
 
        tplg_dbg(" scale: %s\n", elem->id);
 
-       tplg_tlv = calloc(1, sizeof(*tplg_tlv));
-       if (!tplg_tlv)
-               return -ENOMEM;
-
-       elem->tlv = tplg_tlv;
        tplg_tlv->size = sizeof(struct snd_soc_tplg_ctl_tlv);
        tplg_tlv->type = SNDRV_CTL_TLVT_DB_SCALE;
        scale = &tplg_tlv->scale;
diff --git a/src/topology/elem.c b/src/topology/elem.c
index f2076f7958aa..92ca7da4c4aa 100644
--- a/src/topology/elem.c
+++ b/src/topology/elem.c
@@ -20,6 +20,154 @@
 #include "list.h"
 #include "tplg_local.h"
 
+struct tplg_table tplg_table[] = {
+       {
+               .name  = "manifest",
+               .loff  = offsetof(snd_tplg_t, manifest_list),
+               .type  = SND_TPLG_TYPE_MANIFEST,
+               .tsoc  = SND_SOC_TPLG_TYPE_MANIFEST,
+               .size  = sizeof(struct snd_soc_tplg_manifest),
+               .enew  = 1,
+       },
+       {
+               .name  = "control mixer",
+               .loff  = offsetof(snd_tplg_t, mixer_list),
+               .type  = SND_TPLG_TYPE_MIXER,
+               .tsoc  = SND_SOC_TPLG_TYPE_MIXER,
+               .size  = sizeof(struct snd_soc_tplg_mixer_control),
+               .build = 1,
+               .enew  = 1,
+       },
+       {
+               .name  = "control enum",
+               .loff  = offsetof(snd_tplg_t, enum_list),
+               .type  = SND_TPLG_TYPE_ENUM,
+               .tsoc  = SND_SOC_TPLG_TYPE_ENUM,
+               .size  = sizeof(struct snd_soc_tplg_enum_control),
+               .build = 1,
+               .enew  = 1,
+       },
+       {
+               .name  = "control extended (bytes)",
+               .loff  = offsetof(snd_tplg_t, bytes_ext_list),
+               .type  = SND_TPLG_TYPE_BYTES,
+               .tsoc  = SND_SOC_TPLG_TYPE_BYTES,
+               .size  = sizeof(struct snd_soc_tplg_bytes_control),
+               .build = 1,
+               .enew  = 1,
+       },
+       {
+               .name  = "dapm widget",
+               .loff  = offsetof(snd_tplg_t, widget_list),
+               .type  = SND_TPLG_TYPE_DAPM_WIDGET,
+               .tsoc  = SND_SOC_TPLG_TYPE_DAPM_WIDGET,
+               .size  = sizeof(struct snd_soc_tplg_dapm_widget),
+               .build = 1,
+               .enew  = 1,
+       },
+       {
+               .name  = "pcm",
+               .loff  = offsetof(snd_tplg_t, pcm_list),
+               .type  = SND_TPLG_TYPE_PCM,
+               .tsoc  = SND_SOC_TPLG_TYPE_PCM,
+               .size  = sizeof(struct snd_soc_tplg_pcm),
+               .build = 1,
+               .enew  = 1,
+       },
+       {
+               .name  = "physical dai",
+               .loff  = offsetof(snd_tplg_t, dai_list),
+               .type  = SND_TPLG_TYPE_DAI,
+               .tsoc  = SND_SOC_TPLG_TYPE_DAI,
+               .size  = sizeof(struct snd_soc_tplg_dai),
+               .build = 1,
+               .enew  = 1,
+       },
+       {
+               .name  = "be",
+               .loff  = offsetof(snd_tplg_t, be_list),
+               .type  = SND_TPLG_TYPE_BE,
+               .tsoc  = SND_SOC_TPLG_TYPE_BACKEND_LINK,
+               .size  = sizeof(struct snd_soc_tplg_link_config),
+               .build = 1,
+               .enew  = 1,
+       },
+       {
+               .name  = "cc",
+               .loff  = offsetof(snd_tplg_t, cc_list),
+               .type  = SND_TPLG_TYPE_CC,
+               .tsoc  = SND_SOC_TPLG_TYPE_CODEC_LINK,
+               .size  = sizeof(struct snd_soc_tplg_link_config),
+               .build = 1,
+               .enew  = 1,
+       },
+       {
+               .name  = "route (dapm graph)",
+               .loff  = offsetof(snd_tplg_t, route_list),
+               .type  = SND_TPLG_TYPE_DAPM_GRAPH,
+               .tsoc  = SND_SOC_TPLG_TYPE_DAPM_GRAPH,
+               .build = 1,
+       },
+       {
+               .name  = "private data",
+               .loff  = offsetof(snd_tplg_t, pdata_list),
+               .type  = SND_TPLG_TYPE_DATA,
+               .tsoc  = SND_SOC_TPLG_TYPE_PDATA,
+               .build = 1,
+               .enew  = 1,
+       },
+       {
+               .name  = "text",
+               .loff  = offsetof(snd_tplg_t, text_list),
+               .type  = SND_TPLG_TYPE_TEXT,
+               .size  = sizeof(struct tplg_texts),
+               .enew  = 1,
+       },
+       {
+               .name  = "tlv",
+               .loff  = offsetof(snd_tplg_t, tlv_list),
+               .type  = SND_TPLG_TYPE_TLV,
+               .size  = sizeof(struct snd_soc_tplg_ctl_tlv),
+               .enew  = 1,
+       },
+       {
+               .name  = "stream config",
+               .loff  = offsetof(snd_tplg_t, pcm_config_list),
+               .type  = SND_TPLG_TYPE_STREAM_CONFIG,
+               .size  = sizeof(struct snd_soc_tplg_stream),
+               .enew  = 1,
+       },
+       {
+               .name  = "stream capabilities",
+               .loff  = offsetof(snd_tplg_t, pcm_caps_list),
+               .type  = SND_TPLG_TYPE_STREAM_CAPS,
+               .size  = sizeof(struct snd_soc_tplg_stream_caps),
+               .enew  = 1,
+       },
+       {
+               .name  = "token",
+               .loff  = offsetof(snd_tplg_t, token_list),
+               .type  = SND_TPLG_TYPE_TOKEN,
+               .enew  = 1,
+       },
+       {
+               .name  = "tuple",
+               .loff  = offsetof(snd_tplg_t, tuple_list),
+               .type  = SND_TPLG_TYPE_TUPLE,
+               .free  = tplg_free_tuples,
+               .enew  = 1,
+       },
+       {
+               .name  = "hw config",
+               .loff  = offsetof(snd_tplg_t, hw_cfg_list),
+               .type  = SND_TPLG_TYPE_HW_CONFIG,
+               .size  = sizeof(struct snd_soc_tplg_hw_config),
+               .enew  = 1,
+       }
+};
+
+unsigned int tplg_table_items = ARRAY_SIZE(tplg_table);
+
 int tplg_ref_add(struct tplg_elem *elem, int type, const char* id)
 {
        struct tplg_ref *ref;
@@ -152,9 +300,12 @@ struct tplg_elem* tplg_elem_new_common(snd_tplg_t *tplg,
                                       const char *name,
                                       enum snd_tplg_type type)
 {
+       struct tplg_table *tptr;
        struct tplg_elem *elem;
+       struct list_head *list;
        const char *id;
        int obj_size = 0;
+       unsigned index;
        void *obj;
        snd_config_iterator_t i, next;
        snd_config_t *n;
@@ -191,79 +342,24 @@ struct tplg_elem* tplg_elem_new_common(snd_tplg_t *tplg,
        } else if (name != NULL)
                snd_strlcpy(elem->id, name, SNDRV_CTL_ELEM_ID_NAME_MAXLEN);
 
-       switch (type) {
-       case SND_TPLG_TYPE_DATA:
-               tplg_elem_insert(elem, &tplg->pdata_list);
-               break;
-       case SND_TPLG_TYPE_MANIFEST:
-               tplg_elem_insert(elem, &tplg->manifest_list);
-               obj_size = sizeof(struct snd_soc_tplg_manifest);
-               break;
-       case SND_TPLG_TYPE_TEXT:
-               tplg_elem_insert(elem, &tplg->text_list);
-               obj_size = sizeof(struct tplg_texts);
-               break;
-       case SND_TPLG_TYPE_TLV:
-               tplg_elem_insert(elem, &tplg->tlv_list);
-               elem->size = sizeof(struct snd_soc_tplg_ctl_tlv);
-               break;
-       case SND_TPLG_TYPE_BYTES:
-               tplg_elem_insert(elem, &tplg->bytes_ext_list);
-               obj_size = sizeof(struct snd_soc_tplg_bytes_control);
-               break;
-       case SND_TPLG_TYPE_ENUM:
-               tplg_elem_insert(elem, &tplg->enum_list);
-               obj_size = sizeof(struct snd_soc_tplg_enum_control);
-               break;
-       case SND_TPLG_TYPE_MIXER:
-               tplg_elem_insert(elem, &tplg->mixer_list);
-               obj_size = sizeof(struct snd_soc_tplg_mixer_control);
-               break;
-       case SND_TPLG_TYPE_DAPM_WIDGET:
-               tplg_elem_insert(elem, &tplg->widget_list);
-               obj_size = sizeof(struct snd_soc_tplg_dapm_widget);
-               break;
-       case SND_TPLG_TYPE_STREAM_CONFIG:
-               tplg_elem_insert(elem, &tplg->pcm_config_list);
-               obj_size = sizeof(struct snd_soc_tplg_stream);
+       for (index = 0; index < tplg_table_items; index++) {
+               tptr = &tplg_table[index];
+               if (!tptr->enew)
+                       continue;
+               if ((int)type != tptr->type)
+                       continue;
                break;
-       case SND_TPLG_TYPE_STREAM_CAPS:
-               tplg_elem_insert(elem, &tplg->pcm_caps_list);
-               obj_size = sizeof(struct snd_soc_tplg_stream_caps);
-               break;
-       case SND_TPLG_TYPE_PCM:
-               tplg_elem_insert(elem, &tplg->pcm_list);
-               obj_size = sizeof(struct snd_soc_tplg_pcm);
-               break;
-       case SND_TPLG_TYPE_DAI:
-               tplg_elem_insert(elem, &tplg->dai_list);
-               obj_size = sizeof(struct snd_soc_tplg_dai);
-               break;
-       case SND_TPLG_TYPE_BE:
-       case SND_TPLG_TYPE_LINK:
-               tplg_elem_insert(elem, &tplg->be_list);
-               obj_size = sizeof(struct snd_soc_tplg_link_config);
-               break;
-       case SND_TPLG_TYPE_CC:
-               tplg_elem_insert(elem, &tplg->cc_list);
-               obj_size = sizeof(struct snd_soc_tplg_link_config);
-               break;
-       case SND_TPLG_TYPE_TOKEN:
-               tplg_elem_insert(elem, &tplg->token_list);
-               break;
-       case SND_TPLG_TYPE_TUPLE:
-               tplg_elem_insert(elem, &tplg->tuple_list);
-               elem->free = tplg_free_tuples;
-               break;
-       case SND_TPLG_TYPE_HW_CONFIG:
-               tplg_elem_insert(elem, &tplg->hw_cfg_list);
-               obj_size = sizeof(struct snd_soc_tplg_hw_config);
-               break;
-       default:
+       }
+       if (index >= tplg_table_items) {
                free(elem);
                return NULL;
        }
 
+       list = (struct list_head *)((void *)tplg + tptr->loff);
+       tplg_elem_insert(elem, list);
+       obj_size = tptr->size;
+       elem->free = tptr->free;
+
        /* create new object too if required */
        if (obj_size > 0) {
                obj = calloc(1, obj_size);
diff --git a/src/topology/tplg_local.h b/src/topology/tplg_local.h
index 77a681897a85..0987898f8336 100644
--- a/src/topology/tplg_local.h
+++ b/src/topology/tplg_local.h
@@ -196,6 +196,21 @@ struct map_elem {
        int id;
 };
 
+/* mapping table */
+struct tplg_table {
+       const char *name;
+       off_t loff;
+       size_t size;
+       int type;
+       int tsoc;
+       unsigned build: 1;
+       unsigned enew: 1;
+       void (*free)(void *);
+};
+
+extern struct tplg_table tplg_table[];
+extern unsigned int tplg_table_items;
+
 int tplg_parse_compound(snd_tplg_t *tplg, snd_config_t *cfg,
        int (*fcn)(snd_tplg_t *, snd_config_t *, void *),
        void *private);
-- 
2.16.4

++++++ 0042-topology-add-parser-to-the-tplg_table.patch ++++++
>From 4a0efdc87355d5789876e20b9530dc85224ad281 Mon Sep 17 00:00:00 2001
From: Jaroslav Kysela <[email protected]>
Date: Sun, 15 Dec 2019 17:24:50 +0100
Subject: [PATCH 42/63] topology: add parser to the tplg_table

Signed-off-by: Jaroslav Kysela <[email protected]>
---
 src/topology/elem.c       | 35 ++++++++++++++++++
 src/topology/parser.c     | 90 +++++------------------------------------------
 src/topology/tplg_local.h |  3 ++
 3 files changed, 47 insertions(+), 81 deletions(-)

diff --git a/src/topology/elem.c b/src/topology/elem.c
index 92ca7da4c4aa..e79a68b71a91 100644
--- a/src/topology/elem.c
+++ b/src/topology/elem.c
@@ -23,112 +23,139 @@
 struct tplg_table tplg_table[] = {
        {
                .name  = "manifest",
+               .id    = "SectionManifest",
                .loff  = offsetof(snd_tplg_t, manifest_list),
                .type  = SND_TPLG_TYPE_MANIFEST,
                .tsoc  = SND_SOC_TPLG_TYPE_MANIFEST,
                .size  = sizeof(struct snd_soc_tplg_manifest),
                .enew  = 1,
+               .parse = tplg_parse_manifest_data,
        },
        {
                .name  = "control mixer",
+               .id    = "SectionControlMixer",
                .loff  = offsetof(snd_tplg_t, mixer_list),
                .type  = SND_TPLG_TYPE_MIXER,
                .tsoc  = SND_SOC_TPLG_TYPE_MIXER,
                .size  = sizeof(struct snd_soc_tplg_mixer_control),
                .build = 1,
                .enew  = 1,
+               .parse = tplg_parse_control_mixer,
        },
        {
                .name  = "control enum",
+               .id    = "SectionControlEnum",
                .loff  = offsetof(snd_tplg_t, enum_list),
                .type  = SND_TPLG_TYPE_ENUM,
                .tsoc  = SND_SOC_TPLG_TYPE_ENUM,
                .size  = sizeof(struct snd_soc_tplg_enum_control),
                .build = 1,
                .enew  = 1,
+               .parse = tplg_parse_control_enum,
        },
        {
                .name  = "control extended (bytes)",
+               .id    = "SectionControlBytes",
                .loff  = offsetof(snd_tplg_t, bytes_ext_list),
                .type  = SND_TPLG_TYPE_BYTES,
                .tsoc  = SND_SOC_TPLG_TYPE_BYTES,
                .size  = sizeof(struct snd_soc_tplg_bytes_control),
                .build = 1,
                .enew  = 1,
+               .parse = tplg_parse_control_bytes,
        },
        {
                .name  = "dapm widget",
+               .id    = "SectionWidget",
                .loff  = offsetof(snd_tplg_t, widget_list),
                .type  = SND_TPLG_TYPE_DAPM_WIDGET,
                .tsoc  = SND_SOC_TPLG_TYPE_DAPM_WIDGET,
                .size  = sizeof(struct snd_soc_tplg_dapm_widget),
                .build = 1,
                .enew  = 1,
+               .parse = tplg_parse_dapm_widget,
        },
        {
                .name  = "pcm",
+               .id    = "SectionPCM",
                .loff  = offsetof(snd_tplg_t, pcm_list),
                .type  = SND_TPLG_TYPE_PCM,
                .tsoc  = SND_SOC_TPLG_TYPE_PCM,
                .size  = sizeof(struct snd_soc_tplg_pcm),
                .build = 1,
                .enew  = 1,
+               .parse = tplg_parse_pcm,
        },
        {
                .name  = "physical dai",
+               .id    = "SectionDAI",
                .loff  = offsetof(snd_tplg_t, dai_list),
                .type  = SND_TPLG_TYPE_DAI,
                .tsoc  = SND_SOC_TPLG_TYPE_DAI,
                .size  = sizeof(struct snd_soc_tplg_dai),
                .build = 1,
                .enew  = 1,
+               .parse = tplg_parse_dai,
        },
        {
                .name  = "be",
+               .id    = "SectionBE",
+               .id2   = "SectionLink",
                .loff  = offsetof(snd_tplg_t, be_list),
                .type  = SND_TPLG_TYPE_BE,
                .tsoc  = SND_SOC_TPLG_TYPE_BACKEND_LINK,
                .size  = sizeof(struct snd_soc_tplg_link_config),
                .build = 1,
                .enew  = 1,
+               .parse = tplg_parse_link,
        },
        {
                .name  = "cc",
+               .id    = "SectionCC",
                .loff  = offsetof(snd_tplg_t, cc_list),
                .type  = SND_TPLG_TYPE_CC,
                .tsoc  = SND_SOC_TPLG_TYPE_CODEC_LINK,
                .size  = sizeof(struct snd_soc_tplg_link_config),
                .build = 1,
                .enew  = 1,
+               .parse = tplg_parse_cc,
        },
        {
                .name  = "route (dapm graph)",
+               .id = "SectionGraph",
                .loff  = offsetof(snd_tplg_t, route_list),
                .type  = SND_TPLG_TYPE_DAPM_GRAPH,
                .tsoc  = SND_SOC_TPLG_TYPE_DAPM_GRAPH,
                .build = 1,
+               .parse = tplg_parse_dapm_graph,
        },
        {
                .name  = "private data",
+               .id    = "SectionData",
                .loff  = offsetof(snd_tplg_t, pdata_list),
                .type  = SND_TPLG_TYPE_DATA,
                .tsoc  = SND_SOC_TPLG_TYPE_PDATA,
                .build = 1,
                .enew  = 1,
+               .parse = tplg_parse_data,
        },
        {
                .name  = "text",
+               .id    = "SectionText",
                .loff  = offsetof(snd_tplg_t, text_list),
                .type  = SND_TPLG_TYPE_TEXT,
                .size  = sizeof(struct tplg_texts),
                .enew  = 1,
+               .parse = tplg_parse_text,
        },
        {
                .name  = "tlv",
+               .id    = "SectionTLV",
                .loff  = offsetof(snd_tplg_t, tlv_list),
                .type  = SND_TPLG_TYPE_TLV,
                .size  = sizeof(struct snd_soc_tplg_ctl_tlv),
                .enew  = 1,
+               .parse = tplg_parse_tlv,
        },
        {
                .name  = "stream config",
@@ -139,30 +166,38 @@ struct tplg_table tplg_table[] = {
        },
        {
                .name  = "stream capabilities",
+               .id    = "SectionPCMCapabilities",
                .loff  = offsetof(snd_tplg_t, pcm_caps_list),
                .type  = SND_TPLG_TYPE_STREAM_CAPS,
                .size  = sizeof(struct snd_soc_tplg_stream_caps),
                .enew  = 1,
+               .parse = tplg_parse_stream_caps,
        },
        {
                .name  = "token",
+               .id    = "SectionVendorTokens",
                .loff  = offsetof(snd_tplg_t, token_list),
                .type  = SND_TPLG_TYPE_TOKEN,
                .enew  = 1,
+               .parse = tplg_parse_tokens,
        },
        {
                .name  = "tuple",
+               .id    = "SectionVendorTuples",
                .loff  = offsetof(snd_tplg_t, tuple_list),
                .type  = SND_TPLG_TYPE_TUPLE,
                .free  = tplg_free_tuples,
                .enew  = 1,
+               .parse = tplg_parse_tuples,
        },
        {
                .name  = "hw config",
+               .id    = "SectionHWConfig",
                .loff  = offsetof(snd_tplg_t, hw_cfg_list),
                .type  = SND_TPLG_TYPE_HW_CONFIG,
                .size  = sizeof(struct snd_soc_tplg_hw_config),
                .enew  = 1,
+               .parse = tplg_parse_hw_config,
        }
 };
 
diff --git a/src/topology/parser.c b/src/topology/parser.c
index ed864d3223c4..11202769391c 100644
--- a/src/topology/parser.c
+++ b/src/topology/parser.c
@@ -142,87 +142,11 @@ int tplg_parse_compound(snd_tplg_t *tplg, snd_config_t 
*cfg,
 
 static int tplg_parse_config(snd_tplg_t *tplg, snd_config_t *cfg)
 {
-       static struct _parser {
-               const char *id;
-               int (*parser)(snd_tplg_t *tplg, snd_config_t *cfg, void *priv);
-       } *p, parsers[] = {
-               {
-                       .id = "SectionTLV",
-                       .parser = tplg_parse_tlv
-               },
-               {
-                       .id = "SectionControlMixer",
-                       .parser = tplg_parse_control_mixer
-               },
-               {
-                       .id = "SectionControlEnum",
-                       .parser = tplg_parse_control_enum
-               },
-               {
-                       .id = "SectionControlBytes",
-                       .parser = tplg_parse_control_bytes
-               },
-               {
-                       .id = "SectionWidget",
-                       .parser = tplg_parse_dapm_widget
-               },
-               {
-                       .id = "SectionPCMCapabilities",
-                       .parser = tplg_parse_stream_caps
-               },
-               {
-                       .id = "SectionPCM",
-                       .parser = tplg_parse_pcm
-               },
-               {
-                       .id = "SectionDAI",
-                       .parser = tplg_parse_dai
-               },
-               {
-                       .id = "SectionHWConfig",
-                       .parser = tplg_parse_hw_config
-               },
-               {
-                       .id = "SectionLink",
-                       .parser = tplg_parse_link
-               },
-               {
-                       .id = "SectionBE",
-                       .parser = tplg_parse_link
-               },
-               {
-                       .id = "SectionCC",
-                       .parser = tplg_parse_cc
-               },
-               {
-                       .id = "SectionGraph",
-                       .parser = tplg_parse_dapm_graph
-               },
-               {
-                       .id = "SectionText",
-                       .parser = tplg_parse_text
-               },
-               {
-                       .id = "SectionData",
-                       .parser = tplg_parse_data
-               },
-               {
-                       .id = "SectionVendorTokens",
-                       .parser = tplg_parse_tokens
-               },
-               {
-                       .id = "SectionVendorTuples",
-                       .parser = tplg_parse_tuples
-               },
-               {
-                       .id = "SectionManifest",
-                       .parser = tplg_parse_manifest_data
-               },
-       };
        int (*parser)(snd_tplg_t *tplg, snd_config_t *cfg, void *priv);
        snd_config_iterator_t i, next;
        snd_config_t *n;
        const char *id;
+       struct tplg_table *p;
        unsigned int idx;
        int err;
 
@@ -239,10 +163,14 @@ static int tplg_parse_config(snd_tplg_t *tplg, 
snd_config_t *cfg)
                        continue;
 
                parser = NULL;
-               for (idx = 0; idx < ARRAY_SIZE(parsers); idx++) {
-                       p = &parsers[idx];
-                       if (strcmp(id, p->id) == 0) {
-                               parser = p->parser;
+               for (idx = 0; idx < tplg_table_items; idx++) {
+                       p = &tplg_table[idx];
+                       if (p->id && strcmp(id, p->id) == 0) {
+                               parser = p->parse;
+                               break;
+                       }
+                       if (p->id2 && strcmp(id, p->id2) == 0) {
+                               parser = p->parse;
                                break;
                        }
                }
diff --git a/src/topology/tplg_local.h b/src/topology/tplg_local.h
index 0987898f8336..bea88ba35608 100644
--- a/src/topology/tplg_local.h
+++ b/src/topology/tplg_local.h
@@ -199,6 +199,8 @@ struct map_elem {
 /* mapping table */
 struct tplg_table {
        const char *name;
+       const char *id;
+       const char *id2;
        off_t loff;
        size_t size;
        int type;
@@ -206,6 +208,7 @@ struct tplg_table {
        unsigned build: 1;
        unsigned enew: 1;
        void (*free)(void *);
+       int (*parse)(snd_tplg_t *tplg, snd_config_t *cfg, void *priv);
 };
 
 extern struct tplg_table tplg_table[];
-- 
2.16.4

++++++ 0043-topology-add-snd_tplg_save.patch ++++++
++++ 3141 lines (skipped)

++++++ 0044-topology-add-snd_tplg_create-with-flags.patch ++++++
>From b336aea507b80493cdae439f09f710eec4bcd4ae Mon Sep 17 00:00:00 2001
From: Jaroslav Kysela <[email protected]>
Date: Fri, 20 Dec 2019 14:59:00 +0100
Subject: [PATCH 44/63] topology: add snd_tplg_create() with flags

Add SND_TPLG_CREATE_VERBOSE and SND_TPLG_CREATE_DAPM_NOSORT
flags for the special operations.

Signed-off-by: Jaroslav Kysela <[email protected]>
---
 include/topology.h        | 10 ++++++++++
 src/topology/dapm.c       |  5 ++++-
 src/topology/parser.c     | 10 +++++++++-
 src/topology/tplg_local.h |  1 +
 4 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/include/topology.h b/include/topology.h
index 69aa5ed733e3..63c13a9885e9 100644
--- a/include/topology.h
+++ b/include/topology.h
@@ -771,12 +771,22 @@ enum snd_tplg_type {
 /** Fit for all user cases */
 #define SND_TPLG_INDEX_ALL  0
 
+/** Flags for the snd_tplg_create */
+#define SND_TPLG_CREATE_VERBOSE                (1<<0)  /*!< Verbose output */
+#define SND_TPLG_CREATE_DAPM_NOSORT    (1<<1)  /*!< Do not sort DAPM objects 
by index */
+
 /**
  * \brief Create a new topology parser instance.
  * \return New topology parser instance
  */
 snd_tplg_t *snd_tplg_new(void);
 
+/**
+ * \brief Create a new topology parser instance.
+ * \return New topology parser instance
+ */
+snd_tplg_t *snd_tplg_create(int flags);
+
 /**
  * \brief Free a topology parser instance.
  * \param tplg Topology parser instance
diff --git a/src/topology/dapm.c b/src/topology/dapm.c
index 2bdacedca125..d6c15fc1dfaa 100644
--- a/src/topology/dapm.c
+++ b/src/topology/dapm.c
@@ -268,7 +268,10 @@ struct tplg_elem *tplg_elem_new_route(snd_tplg_t *tplg, 
int index)
                return NULL;
 
        elem->index = index;
-       tplg_elem_insert(elem, &tplg->route_list);
+       if (tplg->dapm_sort)
+               tplg_elem_insert(elem, &tplg->route_list);
+       else
+               list_add_tail(&elem->list, &tplg->route_list);
        strcpy(elem->id, "line");
        elem->type = SND_TPLG_TYPE_DAPM_GRAPH;
        elem->size = sizeof(*line);
diff --git a/src/topology/parser.c b/src/topology/parser.c
index de5edd1b6591..8f810f751533 100644
--- a/src/topology/parser.c
+++ b/src/topology/parser.c
@@ -432,7 +432,7 @@ static bool is_little_endian(void)
        return false;
 }
 
-snd_tplg_t *snd_tplg_new(void)
+snd_tplg_t *snd_tplg_create(int flags)
 {
        snd_tplg_t *tplg;
 
@@ -445,6 +445,9 @@ snd_tplg_t *snd_tplg_new(void)
        if (!tplg)
                return NULL;
 
+       tplg->verbose = !!(flags & SND_TPLG_CREATE_VERBOSE);
+       tplg->dapm_sort = (flags & SND_TPLG_CREATE_DAPM_NOSORT) == 0;
+
        tplg->manifest.size = sizeof(struct snd_soc_tplg_manifest);
 
        INIT_LIST_HEAD(&tplg->tlv_list);
@@ -469,6 +472,11 @@ snd_tplg_t *snd_tplg_new(void)
        return tplg;
 }
 
+snd_tplg_t *snd_tplg_new(void)
+{
+       return snd_tplg_create(0);
+}
+
 void snd_tplg_free(snd_tplg_t *tplg)
 {
        free(tplg->bin);
diff --git a/src/topology/tplg_local.h b/src/topology/tplg_local.h
index 42a3aa96ba0e..74b3a55cada4 100644
--- a/src/topology/tplg_local.h
+++ b/src/topology/tplg_local.h
@@ -66,6 +66,7 @@ struct snd_tplg {
        size_t bin_size;
 
        int verbose;
+       unsigned int dapm_sort: 1;
        unsigned int version;
 
        /* runtime state */
-- 
2.16.4

++++++ 0045-topology-add-snd_tplg_version-function.patch ++++++
>From 0793ef064a97afd0b1335af0d187ede227b90582 Mon Sep 17 00:00:00 2001
From: Jaroslav Kysela <[email protected]>
Date: Fri, 20 Dec 2019 21:28:30 +0100
Subject: [PATCH 45/63] topology: add snd_tplg_version() function

Signed-off-by: Jaroslav Kysela <[email protected]>
---
 include/topology.h    | 6 ++++++
 src/topology/parser.c | 5 +++++
 2 files changed, 11 insertions(+)

diff --git a/include/topology.h b/include/topology.h
index 63c13a9885e9..37bced1a4434 100644
--- a/include/topology.h
+++ b/include/topology.h
@@ -775,6 +775,12 @@ enum snd_tplg_type {
 #define SND_TPLG_CREATE_VERBOSE                (1<<0)  /*!< Verbose output */
 #define SND_TPLG_CREATE_DAPM_NOSORT    (1<<1)  /*!< Do not sort DAPM objects 
by index */
 
+/**
+ * \brief Return the version of the topology library.
+ * \return A static string with the version number.
+ */
+const char *snd_tplg_version(void);
+
 /**
  * \brief Create a new topology parser instance.
  * \return New topology parser instance
diff --git a/src/topology/parser.c b/src/topology/parser.c
index 8f810f751533..1eaa24bd42f5 100644
--- a/src/topology/parser.c
+++ b/src/topology/parser.c
@@ -503,3 +503,8 @@ void snd_tplg_free(snd_tplg_t *tplg)
 
        free(tplg);
 }
+
+const char *snd_tplg_version(void)
+{
+       return SND_LIB_VERSION_STR;
+}
-- 
2.16.4

++++++ 0046-topology-cleanup-the-SNDERR-calls.patch ++++++
++++ 876 lines (skipped)

++++++ 0047-topology-dapm-fix-the-SNDERR-Undefined.patch ++++++
>From 712fbacf160f899582a9adc3f30f297211b063bb Mon Sep 17 00:00:00 2001
From: Jaroslav Kysela <[email protected]>
Date: Fri, 27 Dec 2019 19:32:03 +0100
Subject: [PATCH 47/63] topology: dapm - fix the SNDERR() - Undefined

Signed-off-by: Jaroslav Kysela <[email protected]>
---
 src/topology/dapm.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/topology/dapm.c b/src/topology/dapm.c
index f61fe07157ac..88bddca3c08e 100644
--- a/src/topology/dapm.c
+++ b/src/topology/dapm.c
@@ -230,7 +230,7 @@ int tplg_build_routes(snd_tplg_t *tplg)
                                        SND_TPLG_TYPE_MIXER, elem->index) &&
                        !tplg_elem_lookup(&tplg->enum_list, route->control,
                                        SND_TPLG_TYPE_ENUM, elem->index)) {
-                               SNDERR("Undefined mixer/enum control '%s'",
+                               SNDERR("undefined mixer/enum control '%s'",
                                       route->control);
                        }
                }
@@ -243,7 +243,7 @@ int tplg_build_routes(snd_tplg_t *tplg)
                }
                if (!tplg_elem_lookup(&tplg->widget_list, route->source,
                        SND_TPLG_TYPE_DAPM_WIDGET, SND_TPLG_INDEX_ALL)) {
-                       SNDERR("Undefined source widget/stream '%s'",
+                       SNDERR("undefined source widget/stream '%s'",
                               route->source);
                }
 
-- 
2.16.4

++++++ 0048-topology-fix-the-unitialized-tuples.patch ++++++
>From 07d779143bfd24448034cd55945b46c46407247c Mon Sep 17 00:00:00 2001
From: Jaroslav Kysela <[email protected]>
Date: Sat, 28 Dec 2019 10:18:34 +0100
Subject: [PATCH 48/63] topology: fix the unitialized tuples

Signed-off-by: Jaroslav Kysela <[email protected]>
---
 src/topology/data.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/topology/data.c b/src/topology/data.c
index f00ed3011869..4e43fcc9d5a7 100644
--- a/src/topology/data.c
+++ b/src/topology/data.c
@@ -601,6 +601,7 @@ static int copy_tuples(struct tplg_elem *elem,
                elem->data = priv;
 
                array = (struct snd_soc_tplg_vendor_array *)(priv->data + off);
+               memset(array, 0, set_size);
                array->size = set_size;
                array->type = tuple_set->type;
                array->num_elems = tuple_set->num_tuples;
-- 
2.16.4

++++++ 0049-topology-implement-shorter-hexa-uuid-00-00-parser.patch ++++++
>From 2947d83c1322bcdb31c1da180acb0f779a63dcdd Mon Sep 17 00:00:00 2001
From: Jaroslav Kysela <[email protected]>
Date: Sat, 28 Dec 2019 21:44:03 +0100
Subject: [PATCH 49/63] topology: implement shorter hexa uuid 00:00 parser

Signed-off-by: Jaroslav Kysela <[email protected]>
---
 src/topology/data.c | 37 +++++++++++++++++++++++++++++++------
 1 file changed, 31 insertions(+), 6 deletions(-)

diff --git a/src/topology/data.c b/src/topology/data.c
index 4e43fcc9d5a7..1ddd3c509e64 100644
--- a/src/topology/data.c
+++ b/src/topology/data.c
@@ -22,8 +22,8 @@
 #include <ctype.h>
 
 #define UUID_FORMAT "\
-0x%02x, 0x%02x, 0x%02x, 0x%02x, 0x%02x, 0x%02x, 0x%02x, 0x%02x, \
-0x%02x, 0x%02x, 0x%02x, 0x%02x, 0x%02x, 0x%02x, 0x%02x, 0x%02x"
+%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:\
+%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x"
 
 /* Get private data buffer of an element */
 struct snd_soc_tplg_private *get_priv_data(struct tplg_elem *elem)
@@ -316,7 +316,6 @@ format2:
                                values++;
                                s += 2;
                        }
-                       s++;
                }
 
                s++;
@@ -341,6 +340,32 @@ static int get_uuid(const char *str, unsigned char 
*uuid_le)
        if (tmp == NULL)
                return -ENOMEM;
 
+       if (strchr(tmp, ':') == NULL)
+               goto data2;
+
+       s = strtok(tmp, ":");
+       while (s != NULL) {
+               errno = 0;
+               val = strtoul(s, NULL, 16);
+               if ((errno == ERANGE && val == ULONG_MAX)
+                       || (errno != 0 && val == 0)
+                       || (val > UCHAR_MAX)) {
+                       SNDERR("invalid value for uuid");
+                       ret = -EINVAL;
+                       goto out;
+               }
+
+               *(uuid_le + values) = (unsigned char)val;
+
+               values++;
+               if (values >= 16)
+                       break;
+
+               s = strtok(NULL, ":");
+       }
+       goto out;
+
+data2:
        s = strtok(tmp, ",");
 
        while (s != NULL) {
@@ -354,7 +379,7 @@ static int get_uuid(const char *str, unsigned char *uuid_le)
                        goto out;
                }
 
-                *(uuid_le + values) = (unsigned char)val;
+               *(uuid_le + values) = (unsigned char)val;
 
                values++;
                if (values >= 16)
@@ -413,7 +438,7 @@ static int copy_data_hex(char *data, int off, const char 
*str, int width)
                return -ENOMEM;
 
        p += off;
-       s = strtok(tmp, ",");
+       s = strtok(tmp, ",:");
 
        while (s != NULL) {
                ret = write_hex(p, s, width);
@@ -422,7 +447,7 @@ static int copy_data_hex(char *data, int off, const char 
*str, int width)
                        return ret;
                }
 
-               s = strtok(NULL, ",");
+               s = strtok(NULL, ",:");
                p += width;
        }
 
-- 
2.16.4

++++++ 0050-topology-fix-the-TPLG_DEBUG-compilation.patch ++++++
>From 1482d1f254fe42d83d904e52c911df8693b62653 Mon Sep 17 00:00:00 2001
From: Jaroslav Kysela <[email protected]>
Date: Sun, 29 Dec 2019 20:05:14 +0100
Subject: [PATCH 50/63] topology: fix the TPLG_DEBUG compilation

Signed-off-by: Jaroslav Kysela <[email protected]>
---
 src/topology/channel.c | 2 +-
 src/topology/data.c    | 5 ++++-
 src/topology/pcm.c     | 2 +-
 3 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/src/topology/channel.c b/src/topology/channel.c
index 110775a8053d..390c3f164e97 100644
--- a/src/topology/channel.c
+++ b/src/topology/channel.c
@@ -129,7 +129,7 @@ int tplg_parse_channel(snd_tplg_t *tplg, snd_config_t *cfg,
                else if (strcmp(id, "shift") == 0)
                        channel->shift = value;
 
-               tplg_dbg("\t\t%s = %s\n", id, value);
+               tplg_dbg("\t\t%s = %d\n", id, value);
        }
 
        tplg->channel_idx++;
diff --git a/src/topology/data.c b/src/topology/data.c
index 1ddd3c509e64..7b4bdccde602 100644
--- a/src/topology/data.c
+++ b/src/topology/data.c
@@ -230,9 +230,11 @@ err:
        return ret;
 }
 
-static void dump_priv_data(struct tplg_elem *elem)
+static void dump_priv_data(struct tplg_elem *elem ATTRIBUTE_UNUSED)
 {
+#ifdef TPLG_DEBUG
        struct snd_soc_tplg_private *priv = elem->data;
+       unsigned char *p = (unsigned char *)priv->data;
        unsigned int i;
 
        tplg_dbg(" elem size = %d, priv data size = %d\n",
@@ -246,6 +248,7 @@ static void dump_priv_data(struct tplg_elem *elem)
        }
 
        tplg_dbg("\n\n");
+#endif
 }
 
 static inline int check_nibble(unsigned char c)
diff --git a/src/topology/pcm.c b/src/topology/pcm.c
index bc3070816867..8e5afbe6ea72 100644
--- a/src/topology/pcm.c
+++ b/src/topology/pcm.c
@@ -881,7 +881,7 @@ int tplg_parse_pcm(snd_tplg_t *tplg, snd_config_t *cfg,
 
                        pcm->compress = ival;
 
-                       tplg_dbg("\t%s: %s\n", id, val);
+                       tplg_dbg("\t%s: %d\n", id, ival);
                        continue;
                }
 
-- 
2.16.4

++++++ 0051-topology-fix-the-ops-parser-accept-integer-hexa-valu.patch ++++++
>From c765615bce7903a0f3e3d5e7826483708398c184 Mon Sep 17 00:00:00 2001
From: Jaroslav Kysela <[email protected]>
Date: Tue, 31 Dec 2019 15:27:58 +0100
Subject: [PATCH 51/63] topology: fix the ops parser (accept integer/hexa
 values)

Signed-off-by: Jaroslav Kysela <[email protected]>
---
 src/topology/ops.c | 36 +++++++++++++++++++++++++-----------
 1 file changed, 25 insertions(+), 11 deletions(-)

diff --git a/src/topology/ops.c b/src/topology/ops.c
index ad72ef1b2cb6..2885c7814604 100644
--- a/src/topology/ops.c
+++ b/src/topology/ops.c
@@ -67,6 +67,7 @@ int tplg_parse_ops(snd_tplg_t *tplg ATTRIBUTE_UNUSED, 
snd_config_t *cfg,
        snd_config_t *n;
        struct snd_soc_tplg_ctl_hdr *hdr = private;
        const char *id, *value;
+       int ival;
 
        tplg_dbg("\tOps\n");
        hdr->size = sizeof(*hdr);
@@ -80,17 +81,23 @@ int tplg_parse_ops(snd_tplg_t *tplg ATTRIBUTE_UNUSED, 
snd_config_t *cfg,
                        continue;
 
                /* get value - try strings then ints */
-               if (snd_config_get_string(n, &value) < 0)
-                       continue;
+               if (snd_config_get_type(n) == SND_CONFIG_TYPE_STRING) {
+                       if (snd_config_get_string(n, &value) < 0)
+                               continue;
+                       ival = lookup_ops(value);
+               } else {
+                       if (tplg_get_integer(n, &ival, 0))
+                               continue;
+               }
 
                if (strcmp(id, "info") == 0)
-                       hdr->ops.info = lookup_ops(value);
+                       hdr->ops.info = ival;
                else if (strcmp(id, "put") == 0)
-                       hdr->ops.put = lookup_ops(value);
+                       hdr->ops.put = ival;
                else if (strcmp(id, "get") == 0)
-                       hdr->ops.get = lookup_ops(value);
+                       hdr->ops.get = ival;
 
-               tplg_dbg("\t\t%s = %s\n", id, value);
+               tplg_dbg("\t\t%s = %d\n", id, ival);
        }
 
        return 0;
@@ -146,6 +153,7 @@ int tplg_parse_ext_ops(snd_tplg_t *tplg ATTRIBUTE_UNUSED,
        snd_config_t *n;
        struct snd_soc_tplg_bytes_control *be = private;
        const char *id, *value;
+       int ival;
 
        tplg_dbg("\tExt Ops\n");
 
@@ -158,15 +166,21 @@ int tplg_parse_ext_ops(snd_tplg_t *tplg ATTRIBUTE_UNUSED,
                        continue;
 
                /* get value - try strings then ints */
-               if (snd_config_get_string(n, &value) < 0)
-                       continue;
+               if (snd_config_get_type(n) == SND_CONFIG_TYPE_STRING) {
+                       if (snd_config_get_string(n, &value) < 0)
+                               continue;
+                       ival = lookup_ops(value);
+               } else {
+                       if (tplg_get_integer(n, &ival, 0))
+                               continue;
+               }
 
                if (strcmp(id, "info") == 0)
-                       be->ext_ops.info = lookup_ops(value);
+                       be->ext_ops.info = ival;
                else if (strcmp(id, "put") == 0)
-                       be->ext_ops.put = lookup_ops(value);
+                       be->ext_ops.put = ival;
                else if (strcmp(id, "get") == 0)
-                       be->ext_ops.get = lookup_ops(value);
+                       be->ext_ops.get = ival;
 
                tplg_dbg("\t\t%s = %s\n", id, value);
        }
-- 
2.16.4

++++++ 0052-topology-fix-the-wrong-memory-access-object-realloc.patch ++++++
>From 0ba4d6d9c0ae4576f35724d2a5735990f09ceeb0 Mon Sep 17 00:00:00 2001
From: Jaroslav Kysela <[email protected]>
Date: Wed, 1 Jan 2020 19:10:20 +0100
Subject: [PATCH 52/63] topology: fix the wrong memory access (object realloc)

Signed-off-by: Jaroslav Kysela <[email protected]>
---
 src/topology/pcm.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/src/topology/pcm.c b/src/topology/pcm.c
index 8e5afbe6ea72..bd72895971f5 100644
--- a/src/topology/pcm.c
+++ b/src/topology/pcm.c
@@ -252,8 +252,8 @@ static int build_link(snd_tplg_t *tplg, struct tplg_elem 
*elem)
                                ref->id, SND_TPLG_TYPE_HW_CONFIG, elem->index);
                        if (!ref->elem) {
                                SNDERR("cannot find HW config '%s'"
-                               " referenced by link '%s'",
-                               ref->id, elem->id);
+                                      " referenced by link '%s'",
+                                      ref->id, elem->id);
                                return -EINVAL;
                        }
 
@@ -267,6 +267,7 @@ static int build_link(snd_tplg_t *tplg, struct tplg_elem 
*elem)
                        err = tplg_copy_data(tplg, elem, ref);
                        if (err < 0)
                                return err;
+                       link = elem->link; /* realloc */
                        break;
 
                default:
-- 
2.16.4

++++++ 0053-topology-implement-snd_tplg_decode.patch ++++++
++++ 2375 lines (skipped)

++++++ 0054-topology-move-the-elem-list-delete-to-tplg_elem_free.patch ++++++
>From cb88813ff71226af5d16f8853d186ff7c572dbe0 Mon Sep 17 00:00:00 2001
From: Jaroslav Kysela <[email protected]>
Date: Fri, 3 Jan 2020 22:07:11 +0100
Subject: [PATCH 54/63] topology: move the elem->list delete to
 tplg_elem_free()

The tplg_elem_free() is called in the error path from many places
and it is expected that the element object will be unregistered
from the tplg structure, too.

Signed-off-by: Jaroslav Kysela <[email protected]>
---
 src/topology/elem.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/topology/elem.c b/src/topology/elem.c
index ed5b5f13054f..cbd7f4b636c1 100644
--- a/src/topology/elem.c
+++ b/src/topology/elem.c
@@ -301,6 +301,8 @@ struct tplg_elem *tplg_elem_new(void)
 
 void tplg_elem_free(struct tplg_elem *elem)
 {
+       list_del(&elem->list);
+
        tplg_ref_free_list(&elem->ref_list);
 
        /* free struct snd_tplg_ object,
@@ -323,7 +325,6 @@ void tplg_elem_free_list(struct list_head *base)
 
        list_for_each_safe(pos, npos, base) {
                elem = list_entry(pos, struct tplg_elem, list);
-               list_del(&elem->list);
                tplg_elem_free(elem);
        }
 }
-- 
2.16.4

++++++ 0055-topology-unify-the-log-mechanism.patch ++++++
++++ 654 lines (skipped)

++++++ 0056-topology-tplg_dbg-cleanups.patch ++++++
++++ 784 lines (skipped)

++++++ 0057-topology-cosmetic-changes-functions.patch ++++++
>From b20b400e2f598c86abaf697d66396cecd49b3e14 Mon Sep 17 00:00:00 2001
From: Jaroslav Kysela <[email protected]>
Date: Fri, 3 Jan 2020 22:56:48 +0100
Subject: [PATCH 57/63] topology: cosmetic changes (functions)

Signed-off-by: Jaroslav Kysela <[email protected]>
---
 src/topology/builder.c |  3 ++-
 src/topology/ctl.c     |  5 +++--
 src/topology/data.c    | 17 +++++++++--------
 src/topology/parser.c  |  4 ++--
 src/topology/pcm.c     | 16 ++++++++--------
 5 files changed, 24 insertions(+), 21 deletions(-)

diff --git a/src/topology/builder.c b/src/topology/builder.c
index 7af5de084d84..15757668d7d4 100644
--- a/src/topology/builder.c
+++ b/src/topology/builder.c
@@ -71,7 +71,8 @@ static ssize_t write_block_header(snd_tplg_t *tplg, unsigned 
int type,
 }
 
 static int write_elem_block(snd_tplg_t *tplg,
-       struct list_head *base, size_t size, int tplg_type, const char 
*obj_name)
+                           struct list_head *base, size_t size,
+                           int tplg_type, const char *obj_name)
 {
        struct list_head *pos, *sub_pos, *sub_base;
        struct tplg_elem *elem, *elem_next;
diff --git a/src/topology/ctl.c b/src/topology/ctl.c
index 41dc2ddbb826..b78f1c54be05 100644
--- a/src/topology/ctl.c
+++ b/src/topology/ctl.c
@@ -600,7 +600,7 @@ int tplg_save_control_bytes(snd_tplg_t *tplg 
ATTRIBUTE_UNUSED,
 
 /* Parse Control Enums. */
 int tplg_parse_control_enum(snd_tplg_t *tplg, snd_config_t *cfg,
-       void *private ATTRIBUTE_UNUSED)
+                           void *private ATTRIBUTE_UNUSED)
 {
        struct snd_soc_tplg_enum_control *ec;
        struct tplg_elem *elem;
@@ -736,7 +736,8 @@ int tplg_save_control_enum(snd_tplg_t *tplg 
ATTRIBUTE_UNUSED,
  * Mixer control. Supports multiple channels.
  */
 int tplg_parse_control_mixer(snd_tplg_t *tplg,
-       snd_config_t *cfg, void *private ATTRIBUTE_UNUSED)
+                            snd_config_t *cfg,
+                            void *private ATTRIBUTE_UNUSED)
 {
        struct snd_soc_tplg_mixer_control *mc;
        struct tplg_elem *elem;
diff --git a/src/topology/data.c b/src/topology/data.c
index 37c4591987db..b63e98cd7282 100644
--- a/src/topology/data.c
+++ b/src/topology/data.c
@@ -516,7 +516,7 @@ static int tplg_parse_data_hex(snd_config_t *cfg, struct 
tplg_elem *elem,
 
 /* get the token integer value from its id */
 static int get_token_value(const char *token_id,
-       struct tplg_vendor_tokens *tokens)
+                          struct tplg_vendor_tokens *tokens)
 {
        unsigned int i;
 
@@ -589,7 +589,8 @@ unsigned int tplg_get_tuple_size(int type)
 
 /* Add a tuples object to the private buffer of its parent data element */
 static int copy_tuples(struct tplg_elem *elem,
-       struct tplg_vendor_tuples *tuples, struct tplg_vendor_tokens *tokens)
+                      struct tplg_vendor_tuples *tuples,
+                      struct tplg_vendor_tokens *tokens)
 {
        struct snd_soc_tplg_private *priv = elem->data, *priv2;
        struct tplg_tuple_set *tuple_set;
@@ -781,7 +782,7 @@ static const char *get_tuple_type_name(unsigned int type)
 }
 
 static int parse_tuple_set(snd_config_t *cfg,
-       struct tplg_tuple_set **s)
+                          struct tplg_tuple_set **s)
 {
        snd_config_iterator_t i, next;
        snd_config_t *n;
@@ -965,7 +966,7 @@ static int tplg_save_tuple_set(struct tplg_vendor_tuples 
*tuples,
 }
 
 static int parse_tuple_sets(snd_config_t *cfg,
-       struct tplg_vendor_tuples *tuples)
+                           struct tplg_vendor_tuples *tuples)
 {
        snd_config_iterator_t i, next;
        snd_config_t *n;
@@ -1033,7 +1034,7 @@ int tplg_save_tuple_sets(snd_tplg_t *tplg 
ATTRIBUTE_UNUSED,
 /* Parse vendor tokens
  */
 int tplg_parse_tokens(snd_tplg_t *tplg, snd_config_t *cfg,
-       void *private ATTRIBUTE_UNUSED)
+                     void *private ATTRIBUTE_UNUSED)
 {
        snd_config_iterator_t i, next;
        snd_config_t *n;
@@ -1109,7 +1110,7 @@ int tplg_save_tokens(snd_tplg_t *tplg ATTRIBUTE_UNUSED,
 /* Parse vendor tuples.
  */
 int tplg_parse_tuples(snd_tplg_t *tplg, snd_config_t *cfg,
-       void *private ATTRIBUTE_UNUSED)
+                     void *private ATTRIBUTE_UNUSED)
 {
        snd_config_iterator_t i, next;
        snd_config_t *n;
@@ -1193,7 +1194,7 @@ void tplg_free_tuples(void *obj)
 /* Parse manifest's data references
  */
 int tplg_parse_manifest_data(snd_tplg_t *tplg, snd_config_t *cfg,
-       void *private ATTRIBUTE_UNUSED)
+                            void *private ATTRIBUTE_UNUSED)
 {
        struct snd_soc_tplg_manifest *manifest;
        struct tplg_elem *elem;
@@ -1341,7 +1342,7 @@ int tplg_build_manifest_data(snd_tplg_t *tplg)
  * words, tuples.
  */
 int tplg_parse_data(snd_tplg_t *tplg, snd_config_t *cfg,
-       void *private ATTRIBUTE_UNUSED)
+                   void *private ATTRIBUTE_UNUSED)
 {
        snd_config_iterator_t i, next;
        snd_config_t *n;
diff --git a/src/topology/parser.c b/src/topology/parser.c
index d7783a93ab6b..436e48416a43 100644
--- a/src/topology/parser.c
+++ b/src/topology/parser.c
@@ -110,8 +110,8 @@ int tplg_get_unsigned(snd_config_t *n, unsigned *val, int 
base)
  * Parse compound
  */
 int tplg_parse_compound(snd_tplg_t *tplg, snd_config_t *cfg,
-       int (*fcn)(snd_tplg_t *, snd_config_t *, void *),
-       void *private)
+                       int (*fcn)(snd_tplg_t *, snd_config_t *, void *),
+                       void *private)
 {
        const char *id;
        snd_config_iterator_t i, next;
diff --git a/src/topology/pcm.c b/src/topology/pcm.c
index da88783f2b09..61159d33357c 100644
--- a/src/topology/pcm.c
+++ b/src/topology/pcm.c
@@ -1124,8 +1124,8 @@ static int parse_hw_config_refs(snd_tplg_t *tplg 
ATTRIBUTE_UNUSED,
 }
 
 /* Parse a physical link element in text conf file */
-int tplg_parse_link(snd_tplg_t *tplg,
-       snd_config_t *cfg, void *private ATTRIBUTE_UNUSED)
+int tplg_parse_link(snd_tplg_t *tplg, snd_config_t *cfg,
+                   void *private ATTRIBUTE_UNUSED)
 {
        struct snd_soc_tplg_link_config *link;
        struct tplg_elem *elem;
@@ -1264,8 +1264,8 @@ int tplg_save_link(snd_tplg_t *tplg ATTRIBUTE_UNUSED,
 }
 
 /* Parse cc */
-int tplg_parse_cc(snd_tplg_t *tplg,
-       snd_config_t *cfg, void *private ATTRIBUTE_UNUSED)
+int tplg_parse_cc(snd_tplg_t *tplg, snd_config_t *cfg,
+                 void *private ATTRIBUTE_UNUSED)
 {
        struct snd_soc_tplg_link_config *link;
        struct tplg_elem *elem;
@@ -1307,8 +1307,8 @@ int tplg_parse_cc(snd_tplg_t *tplg,
 
 /* save CC */
 int tplg_save_cc(snd_tplg_t *tplg ATTRIBUTE_UNUSED,
-                  struct tplg_elem *elem,
-                  char **dst, const char *pfx)
+                struct tplg_elem *elem,
+                char **dst, const char *pfx)
 {
        struct snd_soc_tplg_link_config *link = elem->link;
        char pfx2[16];
@@ -1668,7 +1668,7 @@ int tplg_save_hw_config(snd_tplg_t *tplg ATTRIBUTE_UNUSED,
 
 /* copy stream object */
 static void tplg_add_stream_object(struct snd_soc_tplg_stream *strm,
-                               struct snd_tplg_stream_template *strm_tpl)
+                                  struct snd_tplg_stream_template *strm_tpl)
 {
        snd_strlcpy(strm->name, strm_tpl->name,
                SNDRV_CTL_ELEM_ID_NAME_MAXLEN);
@@ -1773,7 +1773,7 @@ int tplg_add_pcm_object(snd_tplg_t *tplg, 
snd_tplg_obj_template_t *t)
 
 /* Set link HW config from C API template */
 static int set_link_hw_config(struct snd_soc_tplg_hw_config *cfg,
-                       struct snd_tplg_hw_config_template *tpl)
+                             struct snd_tplg_hw_config_template *tpl)
 {
        unsigned int i;
 
-- 
2.16.4

++++++ 0058-mixer-Fix-memory-leak-for-more-than-16-file-descript.patch ++++++
>From 14ad963e192f101246e9b559d3b3fd41268330fb Mon Sep 17 00:00:00 2001
From: David Fries <[email protected]>
Date: Tue, 7 Jan 2020 09:18:10 -0600
Subject: [PATCH 58/63] mixer: Fix memory leak for more than 16 file descriptor
 case

Signed-off-by: David Fries <[email protected]>
Reviewed-by: Takashi Iwai <[email protected]>
Signed-off-by: Takashi Iwai <[email protected]>
---
 src/mixer/mixer.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/mixer/mixer.c b/src/mixer/mixer.c
index 8205647449d2..b1af99456c8d 100644
--- a/src/mixer/mixer.c
+++ b/src/mixer/mixer.c
@@ -767,7 +767,7 @@ int snd_mixer_wait(snd_mixer_t *mixer, int timeout)
        if (count < 0)
                return count;
        if ((unsigned int) count > sizeof(spfds) / sizeof(spfds[0])) {
-               pfds = malloc(count * sizeof(*pfds));
+               pfds = alloca(count * sizeof(*pfds));
                if (!pfds)
                        return -ENOMEM;
                err = snd_mixer_poll_descriptors(mixer, pfds, 
-- 
2.16.4

++++++ 0059-Quote-strings-containing-or-when-saving-an-alsa-conf.patch ++++++
>From a78dd1bd1e9b47c2aee9b1e066de515b6854695a Mon Sep 17 00:00:00 2001
From: Bertware <[email protected]>
Date: Mon, 13 Jan 2020 10:21:33 +0100
Subject: [PATCH 59/63] Quote strings containing [ or ] when saving an alsa
 config

Signed-off-by: Bert Marcelis <[email protected]>
Signed-off-by: Jaroslav Kysela <[email protected]>
---
 src/conf.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/src/conf.c b/src/conf.c
index c4db9f21a15e..50d0403452a0 100644
--- a/src/conf.c
+++ b/src/conf.c
@@ -1531,6 +1531,8 @@ static void string_print(char *str, int id, snd_output_t 
*out)
        case '.':
        case '{':
        case '}':
+       case '[':
+       case ']':
        case '\'':
        case '"':
                goto quoted;
-- 
2.16.4

++++++ 0060-ucm-fix-the-configuration-directory-longname-for-ucm.patch ++++++
>From b34715004f4a1aabb85c5b9f03ba9f200638ee97 Mon Sep 17 00:00:00 2001
From: Jaroslav Kysela <[email protected]>
Date: Wed, 15 Jan 2020 09:41:05 +0100
Subject: [PATCH 60/63] ucm: fix the configuration directory (longname) for
 ucm2

The new ucm2 expects that the longname directory is shared with
the driver directory. Fix that for 'Syntax 2'.

Signed-off-by: Jaroslav Kysela <[email protected]>
---
 src/ucm/parser.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/ucm/parser.c b/src/ucm/parser.c
index d61124a343e1..b3970a13bf73 100644
--- a/src/ucm/parser.c
+++ b/src/ucm/parser.c
@@ -1649,7 +1649,9 @@ __longname:
 
                if (err == 0) {
                        /* got device-specific file that matches the card long 
name */
-                       snd_strlcpy(uc_mgr->conf_file_name, longname, 
sizeof(uc_mgr->conf_file_name));
+                       if (uc_mgr->conf_format < 2)
+                               snd_strlcpy(uc_mgr->conf_file_name, longname,
+                                           sizeof(uc_mgr->conf_file_name));
                        goto __parse;
                }
        }
-- 
2.16.4

++++++ 0061-ucm-split-conf_file_name-and-conf_dir_name.patch ++++++
>From fe6425af751a768a2ba6cf7d430a85553d3b84f6 Mon Sep 17 00:00:00 2001
From: Jaroslav Kysela <[email protected]>
Date: Wed, 15 Jan 2020 10:31:56 +0100
Subject: [PATCH 61/63] ucm: split conf_file_name and conf_dir_name

With ucm2, the file name might differ from the directory
name. Also, allocate those fields.

Signed-off-by: Jaroslav Kysela <[email protected]>
---
 src/ucm/main.c      |  7 ++++---
 src/ucm/parser.c    | 37 ++++++++++++++++++++++++++-----------
 src/ucm/ucm_local.h |  4 ++--
 src/ucm/ucm_subs.c  |  2 +-
 src/ucm/utils.c     |  4 ++++
 5 files changed, 37 insertions(+), 17 deletions(-)

diff --git a/src/ucm/main.c b/src/ucm/main.c
index 61922f10b7c7..23e15bd8dacb 100644
--- a/src/ucm/main.c
+++ b/src/ucm/main.c
@@ -1700,12 +1700,13 @@ int snd_use_case_get(snd_use_case_mgr_t *uc_mgr,
                err = 0;
        } else if (strcmp(identifier, "_file") == 0) {
                /* get the conf file name of the opened card */
-               if ((uc_mgr->card_name == NULL)
-                   || (uc_mgr->conf_file_name[0] == '\0')) {
+               if ((uc_mgr->card_name == NULL) ||
+                   (uc_mgr->conf_file_name == NULL) ||
+                   (uc_mgr->conf_file_name[0] == '\0')) {
                        err = -ENOENT;
                        goto __end;
                }
-               *value = strndup(uc_mgr->conf_file_name, MAX_FILE);
+               *value = strdup(uc_mgr->conf_file_name);
                if (*value == NULL) {
                        err = -ENOMEM;
                        goto __end;
diff --git a/src/ucm/parser.c b/src/ucm/parser.c
index b3970a13bf73..1bfde0be327d 100644
--- a/src/ucm/parser.c
+++ b/src/ucm/parser.c
@@ -124,6 +124,16 @@ static void configuration_filename(snd_use_case_mgr_t 
*uc_mgr,
        configuration_filename2(fn, fn_len, 2, dir, file, suffix);
 }
 
+/*
+ * Replace mallocated string
+ */
+static char *replace_string(char **dst, const char *value)
+{
+       free(*dst);
+       *dst = strdup(value);
+       return *dst;
+}
+
 /*
  * Parse string
  */
@@ -1186,7 +1196,7 @@ static int parse_verb_file(snd_use_case_mgr_t *uc_mgr,
 
        /* open Verb file for reading */
        configuration_filename(uc_mgr, filename, sizeof(filename),
-                              uc_mgr->conf_file_name, file, "");
+                              uc_mgr->conf_dir_name, file, "");
        err = uc_mgr_config_load(uc_mgr->conf_format, filename, &cfg);
        if (err < 0) {
                uc_error("error: failed to open verb file %s : %d",
@@ -1404,16 +1414,16 @@ static int parse_master_file(snd_use_case_mgr_t 
*uc_mgr, snd_config_t *cfg)
        if (uc_mgr->conf_format >= 2) {
                err = snd_config_search(cfg, "Syntax", &n);
                if (err < 0) {
-                       uc_error("Syntax field not found in %s", 
uc_mgr->conf_file_name);
+                       uc_error("Syntax field not found in %s", 
uc_mgr->conf_dir_name);
                        return -EINVAL;
                }
                err = snd_config_get_integer(n, &l);
                if (err < 0) {
-                       uc_error("Syntax field is invalid in %s", 
uc_mgr->conf_file_name);
+                       uc_error("Syntax field is invalid in %s", 
uc_mgr->conf_dir_name);
                        return err;
                }
                if (l < 2 || l > SYNTAX_VERSION_MAX) {
-                       uc_error("Incompatible syntax %d in %s", l, 
uc_mgr->conf_file_name);
+                       uc_error("Incompatible syntax %d in %s", l, 
uc_mgr->conf_dir_name);
                        return -EINVAL;
                }
                /* delete this field to avoid strcmp() call in the loop */
@@ -1561,8 +1571,9 @@ static int get_by_card(snd_use_case_mgr_t *mgr, const 
char *ctl_name, char *long
                return err;
 
        _name = snd_ctl_card_info_get_name(info);
+       if (replace_string(&mgr->conf_dir_name, _name) == NULL)
+               return -ENOMEM;
        _long_name = snd_ctl_card_info_get_longname(info);
-       snd_strlcpy(mgr->conf_file_name, _name, sizeof(mgr->conf_file_name));
        snd_strlcpy(longname, _long_name, MAX_CARD_LONG_NAME);
 
        return 0;
@@ -1585,7 +1596,7 @@ static int load_master_config(snd_use_case_mgr_t *uc_mgr,
                if (getenv(ALSA_CONFIG_UCM2_VAR) || 
!getenv(ALSA_CONFIG_UCM_VAR)) {
                        uc_mgr->conf_format = 2;
                        configuration_filename(uc_mgr, filename, 
sizeof(filename),
-                                              uc_mgr->conf_file_name, 
card_name, ".conf");
+                                              uc_mgr->conf_dir_name, 
card_name, ".conf");
                        if (access(filename, R_OK) == 0)
                                goto __load;
                }
@@ -1608,6 +1619,9 @@ __load:
                return err;
        }
 
+       if (replace_string(&uc_mgr->conf_file_name, card_name) == NULL)
+               return -ENOMEM;
+
        return 0;
 }
 
@@ -1632,7 +1646,8 @@ int uc_mgr_import_master_config(snd_use_case_mgr_t 
*uc_mgr)
        char longname[MAX_CARD_LONG_NAME];
        int err;
 
-       snd_strlcpy(uc_mgr->conf_file_name, uc_mgr->card_name, 
sizeof(uc_mgr->conf_file_name));
+       if (replace_string(&uc_mgr->conf_dir_name, uc_mgr->card_name) == NULL)
+               return -ENOMEM;
 
        if (strncmp(name, "hw:", 3) == 0) {
                err = get_by_card(uc_mgr, name, longname);
@@ -1650,14 +1665,14 @@ __longname:
                if (err == 0) {
                        /* got device-specific file that matches the card long 
name */
                        if (uc_mgr->conf_format < 2)
-                               snd_strlcpy(uc_mgr->conf_file_name, longname,
-                                           sizeof(uc_mgr->conf_file_name));
+                               snd_strlcpy(uc_mgr->conf_dir_name, longname,
+                                           sizeof(uc_mgr->conf_dir_name));
                        goto __parse;
                }
        }
 
        /* standard path */
-       err = load_master_config(uc_mgr, uc_mgr->conf_file_name, &cfg, 0);
+       err = load_master_config(uc_mgr, uc_mgr->conf_dir_name, &cfg, 0);
        if (err < 0)
                goto __error;
 
@@ -1673,7 +1688,7 @@ __parse:
 
 __error:
        uc_mgr_free_ctl_list(uc_mgr);
-       uc_mgr->conf_file_name[0] = '\0';
+       uc_mgr->conf_dir_name[0] = '\0';
        return err;
 }
 
diff --git a/src/ucm/ucm_local.h b/src/ucm/ucm_local.h
index ba9615078ef8..63e0f3bf1697 100644
--- a/src/ucm/ucm_local.h
+++ b/src/ucm/ucm_local.h
@@ -187,7 +187,6 @@ struct use_case_verb {
        /* verb transition list */
        struct list_head transition_list;
 
-       /* hardware devices that can be used with this use case */
        struct list_head device_list;
 
        /* component device list */
@@ -205,7 +204,8 @@ struct use_case_verb {
  */
 struct snd_use_case_mgr {
        char *card_name;
-       char conf_file_name[MAX_CARD_LONG_NAME];
+       char *conf_file_name;
+       char *conf_dir_name;
        char *comment;
        int conf_format;
 
diff --git a/src/ucm/ucm_subs.c b/src/ucm/ucm_subs.c
index 90e395f0ab6f..d931f603ddd7 100644
--- a/src/ucm/ucm_subs.c
+++ b/src/ucm/ucm_subs.c
@@ -31,7 +31,7 @@
 
 static char *rval_conf_name(snd_use_case_mgr_t *uc_mgr)
 {
-       if (uc_mgr->conf_file_name[0])
+       if (uc_mgr->conf_file_name && uc_mgr->conf_file_name[0])
                return strdup(uc_mgr->conf_file_name);
        return NULL;
 }
diff --git a/src/ucm/utils.c b/src/ucm/utils.c
index cde1d672e7b4..daa568c16a30 100644
--- a/src/ucm/utils.c
+++ b/src/ucm/utils.c
@@ -441,7 +441,11 @@ void uc_mgr_free_verb(snd_use_case_mgr_t *uc_mgr)
        uc_mgr_free_sequence(&uc_mgr->default_list);
        uc_mgr_free_value(&uc_mgr->value_list);
        free(uc_mgr->comment);
+       free(uc_mgr->conf_dir_name);
+       free(uc_mgr->conf_file_name);
        uc_mgr->comment = NULL;
+       uc_mgr->conf_dir_name = NULL;
+       uc_mgr->conf_file_name = NULL;
        uc_mgr->active_verb = NULL;
        INIT_LIST_HEAD(&uc_mgr->active_devices);
        INIT_LIST_HEAD(&uc_mgr->active_modifiers);
-- 
2.16.4

++++++ 0062-ucm-remove-MAX_FILE-definition-and-use-correct-PATH_.patch ++++++
>From ebf5213cd61824b10bcaf67c570919e2a9ea0e1f Mon Sep 17 00:00:00 2001
From: Jaroslav Kysela <[email protected]>
Date: Wed, 15 Jan 2020 10:40:01 +0100
Subject: [PATCH 62/63] ucm: remove MAX_FILE definition and use correct
 PATH_MAX

Signed-off-by: Jaroslav Kysela <[email protected]>
---
 src/ucm/parser.c    | 6 +++---
 src/ucm/ucm_local.h | 1 -
 2 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/src/ucm/parser.c b/src/ucm/parser.c
index 1bfde0be327d..6c13fafdabbf 100644
--- a/src/ucm/parser.c
+++ b/src/ucm/parser.c
@@ -1167,7 +1167,7 @@ static int parse_verb_file(snd_use_case_mgr_t *uc_mgr,
        snd_config_t *n;
        struct use_case_verb *verb;
        snd_config_t *cfg;
-       char filename[MAX_FILE];
+       char filename[PATH_MAX];
        int err;
 
        /* allocate verb */
@@ -1582,7 +1582,7 @@ static int get_by_card(snd_use_case_mgr_t *mgr, const 
char *ctl_name, char *long
 static int load_master_config(snd_use_case_mgr_t *uc_mgr,
                              const char *card_name, snd_config_t **cfg, int 
longname)
 {
-       char filename[MAX_FILE];
+       char filename[PATH_MAX];
        int err;
 
        if (strnlen(card_name, MAX_CARD_LONG_NAME) == MAX_CARD_LONG_NAME) {
@@ -1733,7 +1733,7 @@ static int is_component_directory(const char *dir)
  */
 int uc_mgr_scan_master_configs(const char **_list[])
 {
-       char filename[MAX_FILE], dfl[MAX_FILE];
+       char filename[PATH_MAX], dfl[PATH_MAX];
        char *env = getenv(ALSA_CONFIG_UCM2_VAR);
        const char **list, *d_name;
        snd_config_t *cfg, *c;
diff --git a/src/ucm/ucm_local.h b/src/ucm/ucm_local.h
index 63e0f3bf1697..fa9fc16661bb 100644
--- a/src/ucm/ucm_local.h
+++ b/src/ucm/ucm_local.h
@@ -42,7 +42,6 @@
 
 #define SYNTAX_VERSION_MAX     2
 
-#define MAX_FILE               256
 #define MAX_CARD_SHORT_NAME    32
 #define MAX_CARD_LONG_NAME     80
 
-- 
2.16.4

++++++ 0063-topology-remove-MAX_FILE-definition-and-use-correct-.patch ++++++
>From fbe1ac4a09933f527aff860aad035586367f21b4 Mon Sep 17 00:00:00 2001
From: Jaroslav Kysela <[email protected]>
Date: Wed, 15 Jan 2020 10:41:35 +0100
Subject: [PATCH 63/63] topology: remove MAX_FILE definition and use correct
 PATH_MAX

Signed-off-by: Jaroslav Kysela <[email protected]>
---
 src/topology/data.c       | 2 +-
 src/topology/tplg_local.h | 1 -
 2 files changed, 1 insertion(+), 2 deletions(-)

diff --git a/src/topology/data.c b/src/topology/data.c
index b63e98cd7282..5742b35773f6 100644
--- a/src/topology/data.c
+++ b/src/topology/data.c
@@ -163,7 +163,7 @@ static int tplg_parse_data_file(snd_config_t *cfg, struct 
tplg_elem *elem)
 {
        struct snd_soc_tplg_private *priv = NULL;
        const char *value = NULL;
-       char filename[MAX_FILE];
+       char filename[PATH_MAX];
        char *env = getenv(ALSA_CONFIG_TPLG_VAR);
        FILE *fp;
        size_t size, bytes_read;
diff --git a/src/topology/tplg_local.h b/src/topology/tplg_local.h
index e061db755ed2..5ace0d1919e1 100644
--- a/src/topology/tplg_local.h
+++ b/src/topology/tplg_local.h
@@ -29,7 +29,6 @@
 #define tplg_dbg(fmt, arg...) do { } while (0)
 #endif
 
-#define MAX_FILE               256
 #define TPLG_MAX_PRIV_SIZE     (1024 * 128)
 
 /** The name of the environment variable containing the tplg directory */
-- 
2.16.4





Reply via email to