* [PATCH] ALSA: usb-audio: Tidy up error check for processing unit
@ 2026-04-14 13:29 Rong Zhang
2026-04-15 12:28 ` Takashi Iwai
0 siblings, 1 reply; 2+ messages in thread
From: Rong Zhang @ 2026-04-14 13:29 UTC (permalink / raw)
To: Jaroslav Kysela, Takashi Iwai
Cc: Dan Carpenter, linux-sound, linux-kernel, Rong Zhang
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@rong.moe>
---
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
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] ALSA: usb-audio: Tidy up error check for processing unit
2026-04-14 13:29 [PATCH] ALSA: usb-audio: Tidy up error check for processing unit Rong Zhang
@ 2026-04-15 12:28 ` Takashi Iwai
0 siblings, 0 replies; 2+ messages in thread
From: Takashi Iwai @ 2026-04-15 12:28 UTC (permalink / raw)
To: Rong Zhang
Cc: Jaroslav Kysela, Takashi Iwai, Dan Carpenter, linux-sound,
linux-kernel
On Tue, 14 Apr 2026 15:29:01 +0200,
Rong Zhang wrote:
>
> 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@rong.moe>
Applied now. Thanks.
Takashi
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-04-15 12:28 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-14 13:29 [PATCH] ALSA: usb-audio: Tidy up error check for processing unit Rong Zhang
2026-04-15 12:28 ` Takashi Iwai
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox