Skip to content

Commit 8b0ab7d

Browse files
tiwaigregkh
authored andcommitted
ALSA: usb-audio: Fix parse of UAC2 Extension Units
commit ca95c7b upstream. Extension Unit (XU) is used to have a compatible layout with Processing Unit (PU) on UAC1, and the usb-audio driver code assumed it for parsing the descriptors. Meanwhile, on UAC2, XU became slightly incompatible with PU; namely, XU has a one-byte bmControls bitmap while PU has two bytes bmControls bitmap. This incompatibility results in the read of a wrong address for the last iExtension field, which ended up with an incorrect string for the mixer element name, as recently reported for Focusrite Scarlett 18i20 device. This patch corrects this misalignment by introducing a couple of new macros and calling them depending on the descriptor type. Fixes: 23caaf1 ("ALSA: usb-mixer: Add support for Audio Class v2.0") Reported-by: Stefan Sauer <ensonic@hora-obscura.de> Cc: <stable@vger.kernel.org> Signed-off-by: Takashi Iwai <tiwai@suse.de> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent c8b4e54 commit 8b0ab7d

2 files changed

Lines changed: 47 additions & 6 deletions

File tree

‎include/uapi/linux/usb/audio.h‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,43 @@ static inline __u8 *uac_processing_unit_specific(struct uac_processing_unit_desc
450450
}
451451
}
452452

453+
/*
454+
* Extension Unit (XU) has almost compatible layout with Processing Unit, but
455+
* on UAC2, it has a different bmControls size (bControlSize); it's 1 byte for
456+
* XU while 2 bytes for PU. The last iExtension field is a one-byte index as
457+
* well as iProcessing field of PU.
458+
*/
459+
static inline __u8 uac_extension_unit_bControlSize(struct uac_processing_unit_descriptor *desc,
460+
int protocol)
461+
{
462+
switch (protocol) {
463+
case UAC_VERSION_1:
464+
return desc->baSourceID[desc->bNrInPins + 4];
465+
case UAC_VERSION_2:
466+
return 1; /* in UAC2, this value is constant */
467+
case UAC_VERSION_3:
468+
return 4; /* in UAC3, this value is constant */
469+
default:
470+
return 1;
471+
}
472+
}
473+
474+
static inline __u8 uac_extension_unit_iExtension(struct uac_processing_unit_descriptor *desc,
475+
int protocol)
476+
{
477+
__u8 control_size = uac_extension_unit_bControlSize(desc, protocol);
478+
479+
switch (protocol) {
480+
case UAC_VERSION_1:
481+
case UAC_VERSION_2:
482+
default:
483+
return *(uac_processing_unit_bmControls(desc, protocol)
484+
+ control_size);
485+
case UAC_VERSION_3:
486+
return 0; /* UAC3 does not have this field */
487+
}
488+
}
489+
453490
/* 4.5.2 Class-Specific AS Interface Descriptor */
454491
struct uac1_as_header_descriptor {
455492
__u8 bLength; /* in bytes: 7 */

‎sound/usb/mixer.c‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2303,7 +2303,7 @@ static struct procunit_info extunits[] = {
23032303
*/
23042304
static int build_audio_procunit(struct mixer_build *state, int unitid,
23052305
void *raw_desc, struct procunit_info *list,
2306-
char *name)
2306+
bool extension_unit)
23072307
{
23082308
struct uac_processing_unit_descriptor *desc = raw_desc;
23092309
int num_ins;
@@ -2320,6 +2320,8 @@ static int build_audio_procunit(struct mixer_build *state, int unitid,
23202320
static struct procunit_info default_info = {
23212321
0, NULL, default_value_info
23222322
};
2323+
const char *name = extension_unit ?
2324+
"Extension Unit" : "Processing Unit";
23232325

23242326
if (desc->bLength < 13) {
23252327
usb_audio_err(state->chip, "invalid %s descriptor (id %d)\n", name, unitid);
@@ -2433,7 +2435,10 @@ static int build_audio_procunit(struct mixer_build *state, int unitid,
24332435
} else if (info->name) {
24342436
strlcpy(kctl->id.name, info->name, sizeof(kctl->id.name));
24352437
} else {
2436-
nameid = uac_processing_unit_iProcessing(desc, state->mixer->protocol);
2438+
if (extension_unit)
2439+
nameid = uac_extension_unit_iExtension(desc, state->mixer->protocol);
2440+
else
2441+
nameid = uac_processing_unit_iProcessing(desc, state->mixer->protocol);
24372442
len = 0;
24382443
if (nameid)
24392444
len = snd_usb_copy_string_desc(state->chip,
@@ -2466,10 +2471,10 @@ static int parse_audio_processing_unit(struct mixer_build *state, int unitid,
24662471
case UAC_VERSION_2:
24672472
default:
24682473
return build_audio_procunit(state, unitid, raw_desc,
2469-
procunits, "Processing Unit");
2474+
procunits, false);
24702475
case UAC_VERSION_3:
24712476
return build_audio_procunit(state, unitid, raw_desc,
2472-
uac3_procunits, "Processing Unit");
2477+
uac3_procunits, false);
24732478
}
24742479
}
24752480

@@ -2480,8 +2485,7 @@ static int parse_audio_extension_unit(struct mixer_build *state, int unitid,
24802485
* Note that we parse extension units with processing unit descriptors.
24812486
* That's ok as the layout is the same.
24822487
*/
2483-
return build_audio_procunit(state, unitid, raw_desc,
2484-
extunits, "Extension Unit");
2488+
return build_audio_procunit(state, unitid, raw_desc, extunits, true);
24852489
}
24862490

24872491
/*

0 commit comments

Comments
 (0)