Skip to content

Commit 11bcbc4

Browse files
Daniel Macktiwai
authored andcommitted
ALSA: usb-audio: fix control messages for USB_RECIP_INTERFACE
Control messages directed to an interface must have the interface number set in the lower 8 bits of wIndex. This wasn't done correctly for some clock and mixer messages. Signed-off-by: Daniel Mack <daniel@caiaq.de> Reported-by: Alex Lee <alexlee188@gmail.com> Signed-off-by: Takashi Iwai <tiwai@suse.de>
1 parent d07140b commit 11bcbc4

3 files changed

Lines changed: 16 additions & 6 deletions

File tree

‎sound/usb/clock.c‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@ static int uac_clock_selector_get_val(struct snd_usb_audio *chip, int selector_i
103103
ret = snd_usb_ctl_msg(chip->dev, usb_rcvctrlpipe(chip->dev, 0),
104104
UAC2_CS_CUR,
105105
USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN,
106-
UAC2_CX_CLOCK_SELECTOR << 8, selector_id << 8,
106+
UAC2_CX_CLOCK_SELECTOR << 8,
107+
snd_usb_ctrl_intf(chip) | (selector_id << 8),
107108
&buf, sizeof(buf), 1000);
108109

109110
if (ret < 0)
@@ -120,7 +121,8 @@ static bool uac_clock_source_is_valid(struct snd_usb_audio *chip, int source_id)
120121

121122
err = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), UAC2_CS_CUR,
122123
USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_IN,
123-
UAC2_CS_CONTROL_CLOCK_VALID << 8, source_id << 8,
124+
UAC2_CS_CONTROL_CLOCK_VALID << 8,
125+
snd_usb_ctrl_intf(chip) | (source_id << 8),
124126
&data, sizeof(data), 1000);
125127

126128
if (err < 0) {
@@ -269,7 +271,8 @@ static int set_sample_rate_v2(struct snd_usb_audio *chip, int iface,
269271
data[3] = rate >> 24;
270272
if ((err = snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), UAC2_CS_CUR,
271273
USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_OUT,
272-
UAC2_CS_CONTROL_SAM_FREQ << 8, clock << 8,
274+
UAC2_CS_CONTROL_SAM_FREQ << 8,
275+
snd_usb_ctrl_intf(chip) | (clock << 8),
273276
data, sizeof(data), 1000)) < 0) {
274277
snd_printk(KERN_ERR "%d:%d:%d: cannot set freq %d (v2)\n",
275278
dev->devnum, iface, fmt->altsetting, rate);
@@ -278,7 +281,8 @@ static int set_sample_rate_v2(struct snd_usb_audio *chip, int iface,
278281

279282
if ((err = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), UAC2_CS_CUR,
280283
USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_IN,
281-
UAC2_CS_CONTROL_SAM_FREQ << 8, clock << 8,
284+
UAC2_CS_CONTROL_SAM_FREQ << 8,
285+
snd_usb_ctrl_intf(chip) | (clock << 8),
282286
data, sizeof(data), 1000)) < 0) {
283287
snd_printk(KERN_WARNING "%d:%d:%d: cannot get freq (v2)\n",
284288
dev->devnum, iface, fmt->altsetting);

‎sound/usb/format.c‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,8 @@ static int parse_audio_format_rates_v2(struct snd_usb_audio *chip,
227227
/* get the number of sample rates first by only fetching 2 bytes */
228228
ret = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), UAC2_CS_RANGE,
229229
USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_IN,
230-
UAC2_CS_CONTROL_SAM_FREQ << 8, clock << 8,
230+
UAC2_CS_CONTROL_SAM_FREQ << 8,
231+
snd_usb_ctrl_intf(chip) | (clock << 8),
231232
tmp, sizeof(tmp), 1000);
232233

233234
if (ret < 0) {
@@ -247,7 +248,8 @@ static int parse_audio_format_rates_v2(struct snd_usb_audio *chip,
247248
/* now get the full information */
248249
ret = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), UAC2_CS_RANGE,
249250
USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_IN,
250-
UAC2_CS_CONTROL_SAM_FREQ << 8, clock << 8,
251+
UAC2_CS_CONTROL_SAM_FREQ << 8,
252+
snd_usb_ctrl_intf(chip) | (clock << 8),
251253
data, data_size, 1000);
252254

253255
if (ret < 0) {

‎sound/usb/helper.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,9 @@ unsigned char snd_usb_parse_datainterval(struct snd_usb_audio *chip,
2828
#define snd_usb_get_speed(dev) ((dev)->speed)
2929
#endif
3030

31+
static inline int snd_usb_ctrl_intf(struct snd_usb_audio *chip)
32+
{
33+
return get_iface_desc(chip->ctrl_intf)->bInterfaceNumber;
34+
}
3135

3236
#endif /* __USBAUDIO_HELPER_H */

0 commit comments

Comments
 (0)