mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] ALSA: fm801: add error handling for snd_ctl_add
@ 2018-06-11  8:04 Zhouyang Jia
  2018-06-11  8:49 ` Andy Shevchenko
  0 siblings, 1 reply; 5+ messages in thread
From: Zhouyang Jia @ 2018-06-11  8:04 UTC (permalink / raw)
  Cc: Zhouyang Jia, Jaroslav Kysela, Takashi Iwai, Andy Shevchenko,
	Bhumika Goyal, alsa-devel, linux-kernel

When snd_ctl_add fails, the lack of error-handling code may
cause unexpected results.

This patch adds error-handling code after calling snd_ctl_add.

Signed-off-by: Zhouyang Jia <jiazhouyang09@gmail.com>
---
 sound/pci/fm801.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/sound/pci/fm801.c b/sound/pci/fm801.c
index 73a67bc..e3fb9c6 100644
--- a/sound/pci/fm801.c
+++ b/sound/pci/fm801.c
@@ -1068,11 +1068,19 @@ static int snd_fm801_mixer(struct fm801 *chip)
 		if ((err = snd_ac97_mixer(chip->ac97_bus, &ac97, &chip->ac97_sec)) < 0)
 			return err;
 	}
-	for (i = 0; i < FM801_CONTROLS; i++)
-		snd_ctl_add(chip->card, snd_ctl_new1(&snd_fm801_controls[i], chip));
+	for (i = 0; i < FM801_CONTROLS; i++) {
+		err = snd_ctl_add(chip->card,
+			snd_ctl_new1(&snd_fm801_controls[i], chip));
+		if (err < 0)
+			return err;
+	}
 	if (chip->multichannel) {
-		for (i = 0; i < FM801_CONTROLS_MULTI; i++)
-			snd_ctl_add(chip->card, snd_ctl_new1(&snd_fm801_controls_multi[i], chip));
+		for (i = 0; i < FM801_CONTROLS_MULTI; i++) {
+			err = snd_ctl_add(chip->card,
+				snd_ctl_new1(&snd_fm801_controls_multi[i], chip));
+			if (err < 0)
+				return err;
+		}
 	}
 	return 0;
 }
-- 
2.7.4

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] ALSA: fm801: add error handling for snd_ctl_add
  2018-06-11  8:04 [PATCH] ALSA: fm801: add error handling for snd_ctl_add Zhouyang Jia
@ 2018-06-11  8:49 ` Andy Shevchenko
  2018-06-11 13:24   ` Takashi Iwai
  0 siblings, 1 reply; 5+ messages in thread
From: Andy Shevchenko @ 2018-06-11  8:49 UTC (permalink / raw)
  To: jiazhouyang09, Émeric MASCHINO
  Cc: Jaroslav Kysela, Takashi Iwai, Bhumika Goyal, alsa-devel, linux-kernel

On Mon, 2018-06-11 at 16:04 +0800, jiazhouyang09@gmail.com wrote:
> When snd_ctl_add fails, the lack of error-handling code may
> cause unexpected results.
> 
> This patch adds error-handling code after calling snd_ctl_add.
> 

Acked-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

Though I can't test this (I have FM-only card). Last person who would
able to test was Émeric (Cc'ed).

> Signed-off-by: Zhouyang Jia <jiazhouyang09@gmail.com>
> ---
>  sound/pci/fm801.c | 16 ++++++++++++----
>  1 file changed, 12 insertions(+), 4 deletions(-)
> 
> diff --git a/sound/pci/fm801.c b/sound/pci/fm801.c
> index 73a67bc..e3fb9c6 100644
> --- a/sound/pci/fm801.c
> +++ b/sound/pci/fm801.c
> @@ -1068,11 +1068,19 @@ static int snd_fm801_mixer(struct fm801 *chip)
>  		if ((err = snd_ac97_mixer(chip->ac97_bus, &ac97,
> &chip->ac97_sec)) < 0)
>  			return err;
>  	}
> -	for (i = 0; i < FM801_CONTROLS; i++)
> -		snd_ctl_add(chip->card,
> snd_ctl_new1(&snd_fm801_controls[i], chip));
> +	for (i = 0; i < FM801_CONTROLS; i++) {
> +		err = snd_ctl_add(chip->card,
> +			snd_ctl_new1(&snd_fm801_controls[i], chip));
> +		if (err < 0)
> +			return err;
> +	}
>  	if (chip->multichannel) {
> -		for (i = 0; i < FM801_CONTROLS_MULTI; i++)
> -			snd_ctl_add(chip->card,
> snd_ctl_new1(&snd_fm801_controls_multi[i], chip));
> +		for (i = 0; i < FM801_CONTROLS_MULTI; i++) {
> +			err = snd_ctl_add(chip->card,
> +				snd_ctl_new1(&snd_fm801_controls_mult
> i[i], chip));
> +			if (err < 0)
> +				return err;
> +		}
>  	}
>  	return 0;
>  }

-- 
Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Intel Finland Oy

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] ALSA: fm801: add error handling for snd_ctl_add
  2018-06-11  8:49 ` Andy Shevchenko
@ 2018-06-11 13:24   ` Takashi Iwai
  2018-06-20 19:39     ` Émeric MASCHINO
  0 siblings, 1 reply; 5+ messages in thread
From: Takashi Iwai @ 2018-06-11 13:24 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: "Émeric MASCHINO",
	jiazhouyang09, alsa-devel, BhumikaGoyal, Jaroslav Kysela,
	linux-kernel

On Mon, 11 Jun 2018 10:49:56 +0200,
Andy Shevchenko wrote:
> 
> On Mon, 2018-06-11 at 16:04 +0800, jiazhouyang09@gmail.com wrote:
> > When snd_ctl_add fails, the lack of error-handling code may
> > cause unexpected results.
> > 
> > This patch adds error-handling code after calling snd_ctl_add.
> > 
> 
> Acked-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> 
> Though I can't test this (I have FM-only card). Last person who would
> able to test was Émeric (Cc'ed).

I applied now as this change is pretty safe.


thanks,

Takashi

> 
> > Signed-off-by: Zhouyang Jia <jiazhouyang09@gmail.com>
> > ---
> >  sound/pci/fm801.c | 16 ++++++++++++----
> >  1 file changed, 12 insertions(+), 4 deletions(-)
> > 
> > diff --git a/sound/pci/fm801.c b/sound/pci/fm801.c
> > index 73a67bc..e3fb9c6 100644
> > --- a/sound/pci/fm801.c
> > +++ b/sound/pci/fm801.c
> > @@ -1068,11 +1068,19 @@ static int snd_fm801_mixer(struct fm801 *chip)
> >  		if ((err = snd_ac97_mixer(chip->ac97_bus, &ac97,
> > &chip->ac97_sec)) < 0)
> >  			return err;
> >  	}
> > -	for (i = 0; i < FM801_CONTROLS; i++)
> > -		snd_ctl_add(chip->card,
> > snd_ctl_new1(&snd_fm801_controls[i], chip));
> > +	for (i = 0; i < FM801_CONTROLS; i++) {
> > +		err = snd_ctl_add(chip->card,
> > +			snd_ctl_new1(&snd_fm801_controls[i], chip));
> > +		if (err < 0)
> > +			return err;
> > +	}
> >  	if (chip->multichannel) {
> > -		for (i = 0; i < FM801_CONTROLS_MULTI; i++)
> > -			snd_ctl_add(chip->card,
> > snd_ctl_new1(&snd_fm801_controls_multi[i], chip));
> > +		for (i = 0; i < FM801_CONTROLS_MULTI; i++) {
> > +			err = snd_ctl_add(chip->card,
> > +				snd_ctl_new1(&snd_fm801_controls_mult
> > i[i], chip));
> > +			if (err < 0)
> > +				return err;
> > +		}
> >  	}
> >  	return 0;
> >  }
> 
> -- 
> Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> Intel Finland Oy
> 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] ALSA: fm801: add error handling for snd_ctl_add
  2018-06-11 13:24   ` Takashi Iwai
@ 2018-06-20 19:39     ` Émeric MASCHINO
  2018-06-21  0:34       ` Andy Shevchenko
  0 siblings, 1 reply; 5+ messages in thread
From: Émeric MASCHINO @ 2018-06-20 19:39 UTC (permalink / raw)
  To: Takashi Iwai
  Cc: Andy Shevchenko, jiazhouyang09, alsa-devel, BhumikaGoyal,
	Jaroslav Kysela, linux-kernel

Patch tested on my ia64 workstation. Works flawlessly.

Thanks,

     Émeric


2018-06-11 15:24 GMT+02:00 Takashi Iwai <tiwai@suse.de>:
> On Mon, 11 Jun 2018 10:49:56 +0200,
> Andy Shevchenko wrote:
>>
>> On Mon, 2018-06-11 at 16:04 +0800, jiazhouyang09@gmail.com wrote:
>> > When snd_ctl_add fails, the lack of error-handling code may
>> > cause unexpected results.
>> >
>> > This patch adds error-handling code after calling snd_ctl_add.
>> >
>>
>> Acked-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
>>
>> Though I can't test this (I have FM-only card). Last person who would
>> able to test was Émeric (Cc'ed).
>
> I applied now as this change is pretty safe.
>
>
> thanks,
>
> Takashi
>
>>
>> > Signed-off-by: Zhouyang Jia <jiazhouyang09@gmail.com>
>> > ---
>> >  sound/pci/fm801.c | 16 ++++++++++++----
>> >  1 file changed, 12 insertions(+), 4 deletions(-)
>> >
>> > diff --git a/sound/pci/fm801.c b/sound/pci/fm801.c
>> > index 73a67bc..e3fb9c6 100644
>> > --- a/sound/pci/fm801.c
>> > +++ b/sound/pci/fm801.c
>> > @@ -1068,11 +1068,19 @@ static int snd_fm801_mixer(struct fm801 *chip)
>> >             if ((err = snd_ac97_mixer(chip->ac97_bus, &ac97,
>> > &chip->ac97_sec)) < 0)
>> >                     return err;
>> >     }
>> > -   for (i = 0; i < FM801_CONTROLS; i++)
>> > -           snd_ctl_add(chip->card,
>> > snd_ctl_new1(&snd_fm801_controls[i], chip));
>> > +   for (i = 0; i < FM801_CONTROLS; i++) {
>> > +           err = snd_ctl_add(chip->card,
>> > +                   snd_ctl_new1(&snd_fm801_controls[i], chip));
>> > +           if (err < 0)
>> > +                   return err;
>> > +   }
>> >     if (chip->multichannel) {
>> > -           for (i = 0; i < FM801_CONTROLS_MULTI; i++)
>> > -                   snd_ctl_add(chip->card,
>> > snd_ctl_new1(&snd_fm801_controls_multi[i], chip));
>> > +           for (i = 0; i < FM801_CONTROLS_MULTI; i++) {
>> > +                   err = snd_ctl_add(chip->card,
>> > +                           snd_ctl_new1(&snd_fm801_controls_mult
>> > i[i], chip));
>> > +                   if (err < 0)
>> > +                           return err;
>> > +           }
>> >     }
>> >     return 0;
>> >  }
>>
>> --
>> Andy Shevchenko <andriy.shevchenko@linux.intel.com>
>> Intel Finland Oy
>>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] ALSA: fm801: add error handling for snd_ctl_add
  2018-06-20 19:39     ` Émeric MASCHINO
@ 2018-06-21  0:34       ` Andy Shevchenko
  0 siblings, 0 replies; 5+ messages in thread
From: Andy Shevchenko @ 2018-06-21  0:34 UTC (permalink / raw)
  To: Émeric MASCHINO
  Cc: Takashi Iwai, Andy Shevchenko, Zhouyang Jia,
	ALSA Development Mailing List, BhumikaGoyal, Jaroslav Kysela,
	Linux Kernel Mailing List

On Wed, Jun 20, 2018 at 10:39 PM, Émeric MASCHINO
<emeric.maschino@gmail.com> wrote:
> Patch tested on my ia64 workstation. Works flawlessly.
>

Thanks, Émeric!

-- 
With Best Regards,
Andy Shevchenko

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2018-06-21  0:34 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-06-11  8:04 [PATCH] ALSA: fm801: add error handling for snd_ctl_add Zhouyang Jia
2018-06-11  8:49 ` Andy Shevchenko
2018-06-11 13:24   ` Takashi Iwai
2018-06-20 19:39     ` Émeric MASCHINO
2018-06-21  0:34       ` Andy Shevchenko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome