]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
ALSA: usb-audio: Tidy up error check for processing unit
authorRong Zhang <i@rong.moe>
Tue, 14 Apr 2026 13:29:01 +0000 (21:29 +0800)
committerTakashi Iwai <tiwai@suse.de>
Wed, 15 Apr 2026 12:28:01 +0000 (14:28 +0200)
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/
Signed-off-by: Rong Zhang <i@rong.moe>
Link: https://patch.msgid.link/20260414-uac-build_auto_procunit-refactor-v1-1-afeb7efa6518@rong.moe
Signed-off-by: Takashi Iwai <tiwai@suse.de>
sound/usb/mixer.c

index aa6ea3be100a6be6ef86934f49bcc4321d30d497..85653112e7f3b439a0e53121a7180ccdd5aa34fc 100644 (file)
@@ -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);