From d5caee8d369a4293cea958656146f18c705d4c85 Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Fri, 25 Aug 2006 11:43:22 +0200 Subject: [PATCH] Fix bogus value when no user TLV is defined 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 | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/control/control.c b/src/control/control.c index d0707af7..01f16dc5 100644 --- a/src/control/control.c +++ b/src/control/control.c @@ -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; } /** -- 2.47.1