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

From: Rong Zhang

Date: Tue Apr 14 2026 - 09:30:02 EST


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: Rong Zhang <i@xxxxxxxx>
---
sound/usb/mixer.c | 34 +++++++++++++++-------------------
1 file changed, 15 insertions(+), 19 deletions(-)

diff --git a/sound/usb/mixer.c b/sound/usb/mixer.c
index aa6ea3be100a..85653112e7f3 100644
--- a/sound/usb/mixer.c
+++ b/sound/usb/mixer.c
@@ -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,31 +2697,17 @@ 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;
+ if (err < 0 && err != -EAGAIN) {
+ usb_mixer_elem_info_free(cval);
+ return err;
+ }
}

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

---
base-commit: a1ed2ec1c5458b4a99765439cb595dd0e026a352
change-id: 20260414-uac-build_auto_procunit-refactor-1084afdc365b

Thanks,
Rong