Skip to content

Commit

Permalink
ALSA: usb-audio: fix UAC2 control value queries
Browse files Browse the repository at this point in the history
For RANGE requests, we should only query as much bytes as we're in fact
interested in.

For CUR requests, we shouldn't confuse the firmware with an overlong
request but just ask for 2 bytes.

This might need fixing in the future as it's not entirely clear when to
dispatch 1-byte, 2-byte and 4-byte request blocks. For now, we assume
everything is coded in 16bit - this works for all firmware
implementations I've seen.

Signed-off-by: Daniel Mack <[email protected]>
Reported-by: Alex Lee <[email protected]>
Signed-off-by: Takashi Iwai <[email protected]>
  • Loading branch information
Daniel Mack authored and tiwai committed Jun 11, 2010
1 parent 67c1036 commit e8bdb6b
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions sound/usb/mixer.c
Original file line number Diff line number Diff line change
Expand Up @@ -297,27 +297,36 @@ static int get_ctl_value_v1(struct usb_mixer_elem_info *cval, int request, int v

static int get_ctl_value_v2(struct usb_mixer_elem_info *cval, int request, int validx, int *value_ret)
{
unsigned char buf[14]; /* enough space for one range of 4 bytes */
unsigned char buf[2 + 3*sizeof(__u16)]; /* enough space for one range */
unsigned char *val;
int ret;
int ret, size;
__u8 bRequest;

bRequest = (request == UAC_GET_CUR) ?
UAC2_CS_CUR : UAC2_CS_RANGE;
if (request == UAC_GET_CUR) {
bRequest = UAC2_CS_CUR;
size = sizeof(__u16);
} else {
bRequest = UAC2_CS_RANGE;
size = sizeof(buf);
}

memset(buf, 0, sizeof(buf));

ret = snd_usb_ctl_msg(cval->mixer->chip->dev,
usb_rcvctrlpipe(cval->mixer->chip->dev, 0),
bRequest,
USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN,
validx, cval->mixer->ctrlif | (cval->id << 8),
buf, sizeof(buf), 1000);
buf, size, 1000);

if (ret < 0) {
snd_printk(KERN_ERR "cannot get ctl value: req = %#x, wValue = %#x, wIndex = %#x, type = %d\n",
request, validx, cval->mixer->ctrlif | (cval->id << 8), cval->val_type);
return ret;
}

/* FIXME: how should we handle multiple triplets here? */

switch (request) {
case UAC_GET_CUR:
val = buf;
Expand Down

0 comments on commit e8bdb6b

Please sign in to comment.