Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 68e9fde2 authored by Takashi Iwai's avatar Takashi Iwai
Browse files

ALSA: usb-audio: Simplify parse_audio_unit()



Minor code refactoring by combining the UAC version and the type in
the switch-case flow, so that we reduce the indentation and
redundancy.  One good bonus is that the duplicated definition of the
same type value (e.g. UAC2_EFFECT_UNIT) can be handled more cleanly.

Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent 57f87706
Loading
Loading
Loading
Loading
+39 −56
Original line number Diff line number Diff line
@@ -2782,64 +2782,47 @@ static int parse_audio_unit(struct mixer_build *state, int unitid)
		return 0; /* skip invalid unit */
	}

	if (protocol == UAC_VERSION_1 || protocol == UAC_VERSION_2) {
		switch (p1[2]) {
		case UAC_INPUT_TERMINAL:
#define PTYPE(a, b)	((a) << 8 | (b))
	switch (PTYPE(protocol, p1[2])) {
	case PTYPE(UAC_VERSION_1, UAC_INPUT_TERMINAL):
	case PTYPE(UAC_VERSION_2, UAC_INPUT_TERMINAL):
	case PTYPE(UAC_VERSION_3, UAC_INPUT_TERMINAL):
		return parse_audio_input_terminal(state, unitid, p1);
		case UAC_MIXER_UNIT:
	case PTYPE(UAC_VERSION_1, UAC_MIXER_UNIT):
	case PTYPE(UAC_VERSION_2, UAC_MIXER_UNIT):
	case PTYPE(UAC_VERSION_3, UAC3_MIXER_UNIT):
		return parse_audio_mixer_unit(state, unitid, p1);
		case UAC2_CLOCK_SOURCE:
	case PTYPE(UAC_VERSION_2, UAC2_CLOCK_SOURCE):
	case PTYPE(UAC_VERSION_3, UAC3_CLOCK_SOURCE):
		return parse_clock_source_unit(state, unitid, p1);
		case UAC_SELECTOR_UNIT:
		case UAC2_CLOCK_SELECTOR:
	case PTYPE(UAC_VERSION_1, UAC_SELECTOR_UNIT):
	case PTYPE(UAC_VERSION_2, UAC_SELECTOR_UNIT):
	case PTYPE(UAC_VERSION_3, UAC3_SELECTOR_UNIT):
	case PTYPE(UAC_VERSION_2, UAC2_CLOCK_SELECTOR):
	case PTYPE(UAC_VERSION_3, UAC3_CLOCK_SELECTOR):
		return parse_audio_selector_unit(state, unitid, p1);
		case UAC_FEATURE_UNIT:
	case PTYPE(UAC_VERSION_1, UAC_FEATURE_UNIT):
	case PTYPE(UAC_VERSION_2, UAC_FEATURE_UNIT):
	case PTYPE(UAC_VERSION_3, UAC3_FEATURE_UNIT):
		return parse_audio_feature_unit(state, unitid, p1);
		case UAC1_PROCESSING_UNIT:
		/*   UAC2_EFFECT_UNIT has the same value */
			if (protocol == UAC_VERSION_1)
	case PTYPE(UAC_VERSION_1, UAC1_PROCESSING_UNIT):
	case PTYPE(UAC_VERSION_2, UAC2_PROCESSING_UNIT_V2):
	case PTYPE(UAC_VERSION_3, UAC3_PROCESSING_UNIT):
		return parse_audio_processing_unit(state, unitid, p1);
			else
				return 0; /* FIXME - effect units not implemented yet */
		case UAC1_EXTENSION_UNIT:
		/*   UAC2_PROCESSING_UNIT_V2 has the same value */
			if (protocol == UAC_VERSION_1)
				return parse_audio_extension_unit(state, unitid, p1);
			else /* UAC_VERSION_2 */
				return parse_audio_processing_unit(state, unitid, p1);
		case UAC2_EXTENSION_UNIT_V2:
	case PTYPE(UAC_VERSION_1, UAC1_EXTENSION_UNIT):
	case PTYPE(UAC_VERSION_2, UAC2_EXTENSION_UNIT_V2):
	case PTYPE(UAC_VERSION_3, UAC3_EXTENSION_UNIT):
		return parse_audio_extension_unit(state, unitid, p1);
		default:
			usb_audio_err(state->chip,
				"unit %u: unexpected type 0x%02x\n", unitid, p1[2]);
			return -EINVAL;
		}
	} else { /* UAC_VERSION_3 */
		switch (p1[2]) {
		case UAC_INPUT_TERMINAL:
			return parse_audio_input_terminal(state, unitid, p1);
		case UAC3_MIXER_UNIT:
			return parse_audio_mixer_unit(state, unitid, p1);
		case UAC3_CLOCK_SOURCE:
			return parse_clock_source_unit(state, unitid, p1);
		case UAC3_SELECTOR_UNIT:
		case UAC3_CLOCK_SELECTOR:
			return parse_audio_selector_unit(state, unitid, p1);
		case UAC3_FEATURE_UNIT:
			return parse_audio_feature_unit(state, unitid, p1);
		case UAC3_EFFECT_UNIT:
	case PTYPE(UAC_VERSION_2, UAC2_EFFECT_UNIT):
	case PTYPE(UAC_VERSION_3, UAC3_EFFECT_UNIT):
		return 0; /* FIXME - effect units not implemented yet */
		case UAC3_PROCESSING_UNIT:
			return parse_audio_processing_unit(state, unitid, p1);
		case UAC3_EXTENSION_UNIT:
			return parse_audio_extension_unit(state, unitid, p1);
	default:
		usb_audio_err(state->chip,
				"unit %u: unexpected type 0x%02x\n", unitid, p1[2]);
			      "unit %u: unexpected type 0x%02x\n",
			      unitid, p1[2]);
		return -EINVAL;
	}
}
}

static void snd_usb_mixer_free(struct usb_mixer_interface *mixer)
{