Skip to content

Commit dd02526

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 888b023 commit dd02526

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
@@ -2318,7 +2318,7 @@ static struct procunit_info extunits[] = {
23182318
*/
23192319
static int build_audio_procunit(struct mixer_build *state, int unitid,
23202320
void *raw_desc, struct procunit_info *list,
2321-
char *name)
2321+
bool extension_unit)
23222322
{
23232323
struct uac_processing_unit_descriptor *desc = raw_desc;
23242324
int num_ins;
@@ -2335,6 +2335,8 @@ static int build_audio_procunit(struct mixer_build *state, int unitid,
23352335
static struct procunit_info default_info = {
23362336
0, NULL, default_value_info
23372337
};
2338+
const char *name = extension_unit ?
2339+
"Extension Unit" : "Processing Unit";
23382340

23392341
if (desc->bLength < 13) {
23402342
usb_audio_err(state->chip, "invalid %s descriptor (id %d)\n", name, unitid);
@@ -2448,7 +2450,10 @@ static int build_audio_procunit(struct mixer_build *state, int unitid,
24482450
} else if (info->name) {
24492451
strlcpy(kctl->id.name, info->name, sizeof(kctl->id.name));
24502452
} else {
2451-
nameid = uac_processing_unit_iProcessing(desc, state->mixer->protocol);
2453+
if (extension_unit)
2454+
nameid = uac_extension_unit_iExtension(desc, state->mixer->protocol);
2455+
else
2456+
nameid = uac_processing_unit_iProcessing(desc, state->mixer->protocol);
24522457
len = 0;
24532458
if (nameid)
24542459
len = snd_usb_copy_string_desc(state->chip,
@@ -2481,10 +2486,10 @@ static int parse_audio_processing_unit(struct mixer_build *state, int unitid,
24812486
case UAC_VERSION_2:
24822487
default:
24832488
return build_audio_procunit(state, unitid, raw_desc,
2484-
procunits, "Processing Unit");
2489+
procunits, false);
24852490
case UAC_VERSION_3:
24862491
return build_audio_procunit(state, unitid, raw_desc,
2487-
uac3_procunits, "Processing Unit");
2492+
uac3_procunits, false);
24882493
}
24892494
}
24902495

@@ -2495,8 +2500,7 @@ static int parse_audio_extension_unit(struct mixer_build *state, int unitid,
24952500
* Note that we parse extension units with processing unit descriptors.
24962501
* That's ok as the layout is the same.
24972502
*/
2498-
return build_audio_procunit(state, unitid, raw_desc,
2499-
extunits, "Extension Unit");
2503+
return build_audio_procunit(state, unitid, raw_desc, extunits, true);
25002504
}
25012505

25022506
/*

0 commit comments

Comments
 (0)