All of lore.kernel.org
 help / color / mirror / Atom feed
From: Takashi Sakamoto <o-takashi@sakamocchi.jp>
To: clemens@ladisch.de, tiwai@suse.de
Cc: alsa-devel@alsa-project.org, ffado-devel@lists.sf.net
Subject: [PATCH 3/5] ctl: optimize a test for user-defined element set to older kernels
Date: Wed, 29 Jun 2016 22:43:01 +0900	[thread overview]
Message-ID: <1467207783-19792-4-git-send-email-o-takashi@sakamocchi.jp> (raw)
In-Reply-To: <1467207783-19792-1-git-send-email-o-takashi@sakamocchi.jp>

In Linux 4.0 or former, call of ioctl(2) with SNDRV_CTL_IOCTL_ELEM_ADD
doesn't fill all of identical information in an argument; i.e. numid.
With the kernel, a test of user-defined element set fails.

This commit fixes the bug. The 'numid' field in identical information
is always zero when adding an element set, therefore zero check has an
effect.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
---
 test/user-ctl-element-set.c | 31 ++++++++++++++++++++-----------
 1 file changed, 20 insertions(+), 11 deletions(-)

diff --git a/test/user-ctl-element-set.c b/test/user-ctl-element-set.c
index 09c7929..bfb11d7 100644
--- a/test/user-ctl-element-set.c
+++ b/test/user-ctl-element-set.c
@@ -279,6 +279,7 @@ static int check_elem_set_props(struct elem_set_trial *trial)
 	snd_ctl_elem_id_t *id;
 	snd_ctl_elem_info_t *info;
 	unsigned int numid;
+	unsigned int index;
 	unsigned int i;
 	int err;
 
@@ -286,10 +287,18 @@ static int check_elem_set_props(struct elem_set_trial *trial)
 	snd_ctl_elem_info_alloca(&info);
 
 	snd_ctl_elem_info_set_id(info, trial->id);
-	numid = snd_ctl_elem_info_get_numid(info);
+	numid = snd_ctl_elem_id_get_numid(trial->id);
+	index = snd_ctl_elem_id_get_index(trial->id);
 
 	for (i = 0; i < trial->element_count; ++i) {
-		snd_ctl_elem_info_set_numid(info, numid + i);
+		snd_ctl_elem_info_set_index(info, index + i);
+
+		/*
+		 * In Linux 4.0 or former, ioctl(SNDRV_CTL_IOCTL_ELEM_ADD)
+		 * doesn't fill all of fields for identification.
+		 */
+		if (numid > 0)
+			snd_ctl_elem_info_set_numid(info, numid + i);
 
 		err = snd_ctl_elem_info(trial->handle, info);
 		if (err < 0)
@@ -335,25 +344,25 @@ static int check_elems(struct elem_set_trial *trial)
 {
 	snd_ctl_elem_value_t *data;
 	unsigned int numid;
+	unsigned int index;
 	unsigned int i;
 	int err;
 
 	snd_ctl_elem_value_alloca(&data);
 
 	snd_ctl_elem_value_set_id(data, trial->id);
-
-	/*
-	 * Get the value of numid field in identical information for the first
-	 * element of this element set.
-	 */
-	numid = snd_ctl_elem_value_get_numid(data);
+	numid = snd_ctl_elem_id_get_numid(trial->id);
+	index = snd_ctl_elem_id_get_index(trial->id);
 
 	for (i = 0; i < trial->element_count; ++i) {
+		snd_ctl_elem_value_set_index(data, index + i);
+
 		/*
-		 * Here, I increment numid, while we can also increment offset
-		 * to enumerate each element in this element set.
+		 * In Linux 4.0 or former, ioctl(SNDRV_CTL_IOCTL_ELEM_ADD)
+		 * doesn't fill all of fields for identification.
 		 */
-		snd_ctl_elem_value_set_numid(data, numid + i);
+		if (numid > 0)
+			snd_ctl_elem_value_set_numid(data, numid + i);
 
 		err = snd_ctl_elem_read(trial->handle, data);
 		if (err < 0)
-- 
2.7.4

  parent reply	other threads:[~2016-06-29 13:43 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-29 13:42 [alsa-lib][PATCH 0/5] ctl: support extra information for user-defined element set Takashi Sakamoto
2016-06-29 13:42 ` [PATCH 1/5] ctl: support extra information to " Takashi Sakamoto
2016-06-29 13:43 ` [PATCH 2/5] ctl: add an API to set dimension levels to element information Takashi Sakamoto
2016-06-29 13:43 ` Takashi Sakamoto [this message]
2016-06-29 13:43 ` [PATCH 4/5] ctl: optimize a test for user-defined element set to changes of APIs Takashi Sakamoto
2016-06-29 13:43 ` [PATCH 5/5] ctl: support dimension test for user-defined element set Takashi Sakamoto
2016-06-30  6:54 ` [alsa-lib][PATCH 0/5] ctl: support extra information " Takashi Iwai
2016-06-30 14:22   ` Takashi Sakamoto
2016-06-30 14:42     ` Takashi Iwai

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=1467207783-19792-4-git-send-email-o-takashi@sakamocchi.jp \
    --to=o-takashi@sakamocchi.jp \
    --cc=alsa-devel@alsa-project.org \
    --cc=clemens@ladisch.de \
    --cc=ffado-devel@lists.sf.net \
    --cc=tiwai@suse.de \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.