Re: [PATCH 33/69] ALSA: gus: properly handle snd_ctl_add() error

From: Takashi Iwai
Date: Mon May 03 2021 - 08:28:28 EST


On Mon, 03 May 2021 13:57:00 +0200,
Greg Kroah-Hartman wrote:
>
> From: Kurt Manucredo <fuzzybritches0@xxxxxxxxx>
>
> snd_gus_init_control() does not properly return any possible error that
> might have happened in a call to snd_ctl_add() so resolve this by
> propagating the error back up the call change correctly.
>
> Cc: Takashi Iwai <tiwai@xxxxxxx>
> Signed-off-by: Kurt Manucredo <fuzzybritches0@xxxxxxxxx>
> Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>

This change doesn't look good, either.
It results in the bogus error message "version check failed".

If we really want to fix this, it's better to call
snd_gus_init_control() from snd_gus_initialize() itself while changing
snd_gus_init_control() to return an error code.

However, this error is really not what we should be bothered too
much. Even if a creation of control element failed, it's no fatal
error and nothing really wrong would happen by itself. And, under
such a situation, the system memory is already too tight and the OS
would hang up sooner or later (or OOM killer starts genocide).


thanks,

Takashi

> ---
> sound/isa/gus/gus_main.c | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/sound/isa/gus/gus_main.c b/sound/isa/gus/gus_main.c
> index b7518122a10d..4c2703ea55fb 100644
> --- a/sound/isa/gus/gus_main.c
> +++ b/sound/isa/gus/gus_main.c
> @@ -75,10 +75,11 @@ static const struct snd_kcontrol_new snd_gus_joystick_control = {
> .put = snd_gus_joystick_put
> };
>
> -static void snd_gus_init_control(struct snd_gus_card *gus)
> +static int snd_gus_init_control(struct snd_gus_card *gus)
> {
> if (!gus->ace_flag)
> - snd_ctl_add(gus->card, snd_ctl_new1(&snd_gus_joystick_control, gus));
> + return snd_ctl_add(gus->card, snd_ctl_new1(&snd_gus_joystick_control, gus));
> + return 0;
> }
>
> /*
> @@ -386,8 +387,7 @@ static int snd_gus_check_version(struct snd_gus_card * gus)
> }
> strcpy(card->shortname, card->longname);
> gus->uart_enable = 1; /* standard GUSes doesn't have midi uart trouble */
> - snd_gus_init_control(gus);
> - return 0;
> + return snd_gus_init_control(gus);
> }
>
> int snd_gus_initialize(struct snd_gus_card *gus)
> --
> 2.31.1
>