ALSA: fm801: add error handling for snd_ctl_add
PATCH 1/1 ALSA: fm801: add error handling for snd_ctl_add
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.
--- sound/pci/fm801.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-)
sound/pci/fm801.c +12 -4
@@ -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 ; }
Signature · 1 line
2.7.4
Quoted 5 lines · On Mon, 2018-06-11 at 16:04 +0800, [email protected] wrote:
When
snd_ctl_addfails, the lack of error-handling code may cause unexpected results.This patch adds error-handling code after calling
snd_ctl_add.
Though I can't test this (I have FM-only card). Last person who would able to test was Émeric (Cc'ed).
Quoted 37 lines
Signed-off-by Zhouyang Jia <[email protected]>--- sound/pci/fm801.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-)sound/pci/fm801.c +9
-4@@ -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));
sound/pci/fm801.c +3
-0+if (err <0 ) +return err; + } }return 0 ; }
Signature · 2 lines
Andy Shevchenko <[email protected]> Intel Finland Oy
Quoted 5 lines · Andy Shevchenko
Quoted 3 lines · On Mon, 2018-06-11 at 16:04 +0800, [email protected] wrote:
When
snd_ctl_addfails, the lack of error-handling code may cause unexpected results.
Quoted 7 lines
Quoted 2 lines
This patch adds error-handling code after calling
snd_ctl_add.Acked-by Andy Shevchenko <[email protected]>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
Quoted 43 lines
Quoted 38 lines
Signed-off-by Zhouyang Jia <[email protected]>--- sound/pci/fm801.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-)sound/pci/fm801.c +9
-4@@ -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));
sound/pci/fm801.c +3
-0+if (err <0 ) +return err; + } }return 0 ; }Signature · 2 lines
Andy Shevchenko <[email protected]> Intel Finland Oy
Patch tested on my ia64 workstation. Works flawlessly.
Thanks,
Émeric
2018-06-11 15:24 GMT+02:00 Takashi Iwai <[email protected]>:
Quoted 65 lines
Quoted 5 lines · Andy Shevchenko
Quoted 3 lines · On Mon, 2018-06-11 at 16:04 +0800, [email protected] wrote:
When
snd_ctl_addfails, the lack of error-handling code may cause unexpected results.Quoted 7 lines
Quoted 2 lines
This patch adds error-handling code after calling
snd_ctl_add.Acked-by Andy Shevchenko <[email protected]>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
Quoted 43 lines
Quoted 32 lines
Signed-off-by Zhouyang Jia <[email protected]>--- sound/pci/fm801.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-)sound/pci/fm801.c +9
-4@@ -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));
sound/pci/fm801.c static int snd_fm801_mixer(struct fm801 *chip) · line 1086
Quoted 6 lines
sound/pci/fm801.c +3
-0+if (err <0 ) +return err; + } }return 0 ; }--
Andy Shevchenko <[email protected]> Intel Finland Oy
Quoted 2 lines · Émeric MASCHINO
Patch tested on my ia64 workstation. Works flawlessly.
Thanks, Émeric!
Signature · 2 lines
With Best Regards, Andy Shevchenko