]> git.alsa-project.org Git - alsa-lib.git/commitdiff
Fix bogus value when no user TLV is defined
authorTakashi Iwai <tiwai@suse.de>
Fri, 25 Aug 2006 09:43:22 +0000 (11:43 +0200)
committerTakashi Iwai <tiwai@suse.de>
Fri, 25 Aug 2006 09:43:22 +0000 (11:43 +0200)
Check whether non-zero size TLV is really returned by comparing
with the pre-filled pattern.  ALSA 1.0.12 driver doesn't notify
the error even if user TLV is empty, so the previous value is
passed bogusly.

src/control/control.c

index d0707af718128ccf4aa64bfd688680f01691c703..01f16dc50a1facad07061659d95d21579ec33ec9 100644 (file)
@@ -455,8 +455,21 @@ static int snd_ctl_tlv_do(snd_ctl_t *ctl, int op_flag,
 int snd_ctl_elem_tlv_read(snd_ctl_t *ctl, const snd_ctl_elem_id_t *id,
                          unsigned int *tlv, unsigned int tlv_size)
 {
+       int err;
        assert(ctl && id && (id->name[0] || id->numid) && tlv);
-       return snd_ctl_tlv_do(ctl, 0, id, tlv, tlv_size);
+       if (tlv_size < 2 * sizeof(int))
+               return -EINVAL;
+       /* 1.0.12 driver doesn't return the error even if the user TLV
+        * is empty.  So, initialize TLV here with an invalid type
+        * and compare the returned value after ioctl for checking
+        * the validity of TLV.
+        */
+       tlv[0] = -1;
+       tlv[1] = 0;
+       err = snd_ctl_tlv_do(ctl, 0, id, tlv, tlv_size);
+       if (err >= 0 && tlv[0] == -1)
+               err = -ENXIO;
+       return err;
 }
 
 /**