Commit 37a6b2d6 authored by Rong Zhang's avatar Rong Zhang Committed by Takashi Iwai
Browse files

ALSA: usb-audio: Tidy up error check for processing unit

There are two duplicated code paths calling get_min_max() with the same
arguments in build_audio_procunit(). This once led to a failure to
notice a code path that caused the `err' variable uninitialized when
adding error checks for callers of get_min_max*() [1].

Move cases in the switch-case statement to tidy up the error check by
merging the duplicated code paths together with a fallthrough attribute.
This also eliminates the `err = 0' lines and aggregates the error check
along with the corresponding call together, so that the intent of these
code paths is clearer.

The refactor also has an interesting effect that shrinks the .text size
by 16 bytes (GCC 15 amd64). It seems that the compiler was unable to
perform dead code elimination for the `err = 0' paths before.

Link: https://lore.kernel.org/r/ad36dGpCBTGsyFr_@stanley.mountain/

 [1]
Signed-off-by: default avatarRong Zhang <i@rong.moe>
Link: https://patch.msgid.link/20260414-uac-build_auto_procunit-refactor-v1-1-afeb7efa6518@rong.moe


Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent 02df59d0
Loading
Loading
Loading
Loading
+15 −19
Original line number Diff line number Diff line
@@ -2664,6 +2664,16 @@ static int build_audio_procunit(struct mixer_build *state, int unitid,

		/* get min/max values */
		switch (type) {
		case USB_XU_CLOCK_RATE:
			/*
			 * E-Mu USB 0404/0202/TrackerPre/0204
			 * samplerate control quirk
			 */
			cval->min = 0;
			cval->max = 5;
			cval->res = 1;
			cval->initialized = 1;
			break;
		case UAC_PROCESS_UP_DOWNMIX: {
			bool mode_sel = false;

@@ -2687,32 +2697,18 @@ static int build_audio_procunit(struct mixer_build *state, int unitid,
				cval->max = control_spec[0];
				cval->res = 1;
				cval->initialized = 1;
				err = 0;
				break;
			}

			err = get_min_max(cval, valinfo->min_value);
			break;
			fallthrough;
		}
		case USB_XU_CLOCK_RATE:
			/*
			 * E-Mu USB 0404/0202/TrackerPre/0204
			 * samplerate control quirk
			 */
			cval->min = 0;
			cval->max = 5;
			cval->res = 1;
			cval->initialized = 1;
			err = 0;
			break;
		default:
			err = get_min_max(cval, valinfo->min_value);
			break;
		}
			if (err < 0 && err != -EAGAIN) {
				usb_mixer_elem_info_free(cval);
				return err;
			}
		}

		err = get_cur_ctl_value(cval, cval->control << 8, &val);
		if (err < 0) {