ALSA: usb-audio: Fix missing error handling for get_min_max*()
PATCH 1/1 ALSA: usb-audio: Fix missing error handling for get_min_max*()
The recent fix to add the error return value check from get_min_max*() missed one case in build_audio_procunit() where no error value is set. This may lead to an uninitialized variable and confuse the caller (although this wouldn't happen practically because err is set for the loop of num_ins at the beginning of the funciton).
Fix it by setting "err = 0" properly at the missing case, too.
--- sound/usb/mixer.c | 1 + 1 file changed, 1 insertion(+)
sound/usb/mixer.c +1 -0
@@ -2687,6 +2687,7 @@ 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 ; }
Signature · 1 line
2.53.0
Hi Takashi,
Quoted 21 lines · Takashi Iwai
The recent fix to add the error return value check from get_min_max*() missed one case in
build_audio_procunit()where no error value is set. This may lead to an uninitialized variable and confuse the caller (although this wouldn't happen practically because err is set for the loop ofnum_insat the beginning of the funciton).Fix it by setting "err = 0" properly at the missing case, too.
Fixes 4f55a85cd4fc ("ALSA: usb-audio: Add error checks against get_min_max*()")Reported-by Dan Carpenter <[email protected]>Signed-off-by Takashi Iwai <[email protected]>--- sound/usb/mixer.c | 1 + 1 file changed, 1 insertion(+)sound/usb/mixer.c +0
-0
sound/usb/mixer.c static int build_audio_procunit(struct mixer_build *state, int unitid, · line 2690
Quoted 4 lines
sound/usb/mixer.c +1
-0@@ -2687,6 +2687,7 @@ static int build_audio_procunit(struct mixer_build *state, int unitid, cval->max = control_spec[0 ]; cval->res =1 ; cval->initialized =1 ; + err =0 ;
Whoops, it's my fault that I didn't noticed the code path.
I think we can make the UAC_PROCESS_UP_DOWNMIX case fall through the default case so that we can move the error check into the latter and get rid of all `err = 0'. Doing so also improves readability and prevents similar mistakes in future changes. Perhaps I should have done this in my previous refactoring patch...
I just noticed that you've applied this patch to your tree. If my proposed refactor makes sense to you, I will send a patch for it.
Thanks,
Rong
Quoted 3 lines
sound/usb/mixer.c +0
-0break ; }
Quoted 32 lines · Rong Zhang
Hi Takashi,
Quoted 21 lines · Takashi Iwai
The recent fix to add the error return value check from get_min_max*() missed one case in
build_audio_procunit()where no error value is set. This may lead to an uninitialized variable and confuse the caller (although this wouldn't happen practically because err is set for the loop ofnum_insat the beginning of the funciton).Fix it by setting "err = 0" properly at the missing case, too.
Fixes 4f55a85cd4fc ("ALSA: usb-audio: Add error checks against get_min_max*()")Reported-by Dan Carpenter <[email protected]>Signed-off-by Takashi Iwai <[email protected]>--- sound/usb/mixer.c | 1 + 1 file changed, 1 insertion(+)sound/usb/mixer.c +0
-0sound/usb/mixer.c static int build_audio_procunit(struct mixer_build *state, int unitid, · line 2690
Quoted 4 lines
sound/usb/mixer.c +1
-0@@ -2687,6 +2687,7 @@ static int build_audio_procunit(struct mixer_build *state, int unitid, cval->max = control_spec[0 ]; cval->res =1 ; cval->initialized =1 ; + err =0 ;Whoops, it's my fault that I didn't noticed the code path.
Quoted 8 lines
I think we can make the
UAC_PROCESS_UP_DOWNMIXcase fall through the default case so that we can move the error check into the latter and get rid of all `err = 0'. Doing so also improves readability and prevents similar mistakes in future changes. Perhaps I should have done this in my previous refactoring patch...I just noticed that you've applied this patch to your tree. If my proposed refactor makes sense to you, I will send a patch for it.
That was my another idea, too. OTOH, I thought handling the success error code explicitly makes it clearer that the code handles it.
It's pretty nuance, and I'm open for either option, so feel free to submit a cleanup patch on the top.
thanks,
Takashi