alsa-devel.alsa-project.org archive mirror
 help / color / mirror / Atom feed
From: Piotr Maziarz <piotrx.maziarz@linux.intel.com>
To: alsa-devel@alsa-project.org
Cc: cezary.rojewski@intel.com, amadeuszx.slawinski@intel.com
Subject: [PATCH v2 06/10] topology: decode: Change declaration of enum decoding function
Date: Mon,  6 Jul 2020 11:05:59 +0200	[thread overview]
Message-ID: <1594026363-30276-7-git-send-email-piotrx.maziarz@linux.intel.com> (raw)
In-Reply-To: <1594026363-30276-1-git-send-email-piotrx.maziarz@linux.intel.com>

Size constraints are always checked before invoking
tplg_decode_control_enum1. There is no need to validate it twice.
Alos moved debug print about size to invoking function, since now it's it
responsibility to check size.

Change-Id: I8bdd93cb1534ae9217aee87cb2b267e175aa483f
---
 src/topology/ctl.c        | 19 +++++--------------
 src/topology/dapm.c       |  3 +--
 src/topology/tplg_local.h |  2 +-
 3 files changed, 7 insertions(+), 17 deletions(-)

diff --git a/src/topology/ctl.c b/src/topology/ctl.c
index 1f39846..47db400 100644
--- a/src/topology/ctl.c
+++ b/src/topology/ctl.c
@@ -1335,22 +1335,10 @@ int tplg_decode_control_enum1(snd_tplg_t *tplg,
 			      struct list_head *heap,
 			      struct snd_tplg_enum_template *et,
 			      size_t pos,
-			      void *bin, size_t size)
+			      struct snd_soc_tplg_enum_control *ec)
 {
-	struct snd_soc_tplg_enum_control *ec = bin;
 	int i;
 
-	if (size < sizeof(*ec)) {
-		SNDERR("enum: small size %d", size);
-		return -EINVAL;
-	}
-
-	tplg_log(tplg, 'D', pos, "enum: size %d private size %d",
-		 ec->size, ec->priv.size);
-	if (size != ec->size + ec->priv.size) {
-		SNDERR("enum: unexpected element size %d", size);
-		return -EINVAL;
-	}
 	if (ec->num_channels > SND_TPLG_MAX_CHAN ||
 	    ec->num_channels > SND_SOC_TPLG_MAX_CHAN) {
 		SNDERR("enum: unexpected channel count %d", ec->num_channels);
@@ -1427,7 +1415,10 @@ next:
 		return -EINVAL;
 	}
 
-	err = tplg_decode_control_enum1(tplg, &heap, &et, pos, bin, size);
+	tplg_log(tplg, 'D', pos, "enum: size %d private size %d",
+		 ec->size, ec->priv.size);
+
+	err = tplg_decode_control_enum1(tplg, &heap, &et, pos, ec);
 	if (err >= 0) {
 		t.enum_ctl = &et;
 		err = snd_tplg_add_object(tplg, &t);
diff --git a/src/topology/dapm.c b/src/topology/dapm.c
index cd1a877..73a9390 100644
--- a/src/topology/dapm.c
+++ b/src/topology/dapm.c
@@ -972,8 +972,7 @@ next:
 				err = -EINVAL;
 				goto retval;
 			}
-			err = tplg_decode_control_enum1(tplg, &heap, et, pos,
-							bin, size2);
+			err = tplg_decode_control_enum1(tplg, &heap, et, pos, ec);
 			break;
 		case SND_SOC_TPLG_TYPE_BYTES:
 			bt = tplg_calloc(&heap, sizeof(*bt));
diff --git a/src/topology/tplg_local.h b/src/topology/tplg_local.h
index 5ace0d1..acb01a8 100644
--- a/src/topology/tplg_local.h
+++ b/src/topology/tplg_local.h
@@ -398,7 +398,7 @@ int tplg_decode_control_enum1(snd_tplg_t *tplg,
 			      struct list_head *heap,
 			      struct snd_tplg_enum_template *et,
 			      size_t pos,
-			      void *bin, size_t size);
+			      struct snd_soc_tplg_enum_control *ec);
 int tplg_decode_control_enum(snd_tplg_t *tplg, size_t pos,
 			     struct snd_soc_tplg_hdr *hdr,
 			     void *bin, size_t size);
-- 
2.7.4


  parent reply	other threads:[~2020-07-06 10:12 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-06  9:05 [PATCH v2 00/10] topology: decode: Various fixes Piotr Maziarz
2020-07-06  9:05 ` [PATCH v2 01/10] topology: decode: Fix channel map memory allocation Piotr Maziarz
2020-07-06  9:05 ` [PATCH v2 02/10] topology: decode: Fix infinite loop in decoding enum control Piotr Maziarz
2020-07-06  9:05 ` [PATCH v2 03/10] topology: decode: Remove decoding values for " Piotr Maziarz
2020-07-06 19:54   ` Pierre-Louis Bossart
2020-07-06  9:05 ` [PATCH v2 04/10] topology: decode: Add enum control texts as separate element Piotr Maziarz
2020-07-06  9:05 ` [PATCH v2 05/10] topology: decode: Fix printing texts section Piotr Maziarz
2020-07-06  9:05 ` Piotr Maziarz [this message]
2020-07-06  9:06 ` [PATCH v2 07/10] topology: decode: Fix decoding PCM formats and rates Piotr Maziarz
2020-07-06 19:58   ` Pierre-Louis Bossart
2020-07-06  9:06 ` [PATCH v2 08/10] topology: decode: Print sig_bits field in PCM capabilities section Piotr Maziarz
2020-07-06  9:06 ` [PATCH v2 09/10] topology: decode: Add DAI name printing Piotr Maziarz
2020-07-06  9:06 ` [PATCH v2 10/10] topology: Make buffer for saving dynamic size Piotr Maziarz
2020-07-06 20:01 ` [PATCH v2 00/10] topology: decode: Various fixes Pierre-Louis Bossart
2020-07-14 12:13   ` Piotr Maziarz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1594026363-30276-7-git-send-email-piotrx.maziarz@linux.intel.com \
    --to=piotrx.maziarz@linux.intel.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=amadeuszx.slawinski@intel.com \
    --cc=cezary.rojewski@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).