]> git.alsa-project.org Git - alsa-lib.git/commitdiff
ctl: optimize a test for user-defined element set to older kernels
authorTakashi Sakamoto <o-takashi@sakamocchi.jp>
Wed, 29 Jun 2016 13:43:01 +0000 (22:43 +0900)
committerTakashi Iwai <tiwai@suse.de>
Thu, 30 Jun 2016 06:42:17 +0000 (08:42 +0200)
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>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
test/user-ctl-element-set.c

index 09c792917cec5077cdb599f5c771493a0586ab5b..bfb11d7f73da645f0171fd0f5013253128fe96ed 100644 (file)
@@ -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)