linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ALSA: sonicvibes: add error handling for snd_ctl_add
@ 2018-06-11  8:08 Zhouyang Jia
  2018-06-11 13:26 ` Takashi Iwai
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Zhouyang Jia @ 2018-06-11  8:08 UTC (permalink / raw)
  Cc: Zhouyang Jia, Jaroslav Kysela, Takashi Iwai, 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/sonicvibes.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/sound/pci/sonicvibes.c b/sound/pci/sonicvibes.c
index a8abb15..57cb77a 100644
--- a/sound/pci/sonicvibes.c
+++ b/sound/pci/sonicvibes.c
@@ -1188,6 +1188,7 @@ SONICVIBES_SINGLE("Joystick Speed", 0, SV_IREG_GAME_PORT, 1, 15, 0);
 static int snd_sonicvibes_create_gameport(struct sonicvibes *sonic)
 {
 	struct gameport *gp;
+	int err;
 
 	sonic->gameport = gp = gameport_allocate_port();
 	if (!gp) {
@@ -1203,7 +1204,10 @@ static int snd_sonicvibes_create_gameport(struct sonicvibes *sonic)
 
 	gameport_register_port(gp);
 
-	snd_ctl_add(sonic->card, snd_ctl_new1(&snd_sonicvibes_game_control, sonic));
+	err = snd_ctl_add(sonic->card,
+		snd_ctl_new1(&snd_sonicvibes_game_control, sonic));
+	if (err < 0)
+		return err;
 
 	return 0;
 }
-- 
2.7.4

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

* Re: [PATCH] ALSA: sonicvibes: add error handling for snd_ctl_add
  2018-06-11  8:08 [PATCH] ALSA: sonicvibes: add error handling for snd_ctl_add Zhouyang Jia
@ 2018-06-11 13:26 ` Takashi Iwai
  2018-06-14 11:22 ` [PATCH v2] " Zhouyang Jia
  2018-06-14 11:41 ` [PATCH v3] " Zhouyang Jia
  2 siblings, 0 replies; 6+ messages in thread
From: Takashi Iwai @ 2018-06-11 13:26 UTC (permalink / raw)
  To: Zhouyang Jia; +Cc: alsa-devel, Bhumika Goyal, Jaroslav Kysela, linux-kernel

On Mon, 11 Jun 2018 10:08:40 +0200,
Zhouyang Jia 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.
> 
> Signed-off-by: Zhouyang Jia <jiazhouyang09@gmail.com>

I postpone this one because the change won't give anything as is
although this change itself is correct.  If you look at the code
closely, the caller of snd_sonicvibes_create_gameport() ignores the
return value.
So we need to fix two places.


thanks,

Takashi

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

* [PATCH v2] ALSA: sonicvibes: add error handling for snd_ctl_add
  2018-06-11  8:08 [PATCH] ALSA: sonicvibes: add error handling for snd_ctl_add Zhouyang Jia
  2018-06-11 13:26 ` Takashi Iwai
@ 2018-06-14 11:22 ` Zhouyang Jia
  2018-06-14 11:30   ` Takashi Iwai
  2018-06-14 11:41 ` [PATCH v3] " Zhouyang Jia
  2 siblings, 1 reply; 6+ messages in thread
From: Zhouyang Jia @ 2018-06-14 11:22 UTC (permalink / raw)
  Cc: Zhouyang Jia, Jaroslav Kysela, Takashi Iwai, 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>
---
v1->v2:
- Check the return value of snd_sonicvibes_create_gameport.
---
 sound/pci/sonicvibes.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/sound/pci/sonicvibes.c b/sound/pci/sonicvibes.c
index a8abb15..75225b04 100644
--- a/sound/pci/sonicvibes.c
+++ b/sound/pci/sonicvibes.c
@@ -1188,6 +1188,7 @@ SONICVIBES_SINGLE("Joystick Speed", 0, SV_IREG_GAME_PORT, 1, 15, 0);
 static int snd_sonicvibes_create_gameport(struct sonicvibes *sonic)
 {
 	struct gameport *gp;
+	int err;
 
 	sonic->gameport = gp = gameport_allocate_port();
 	if (!gp) {
@@ -1203,7 +1204,10 @@ static int snd_sonicvibes_create_gameport(struct sonicvibes *sonic)
 
 	gameport_register_port(gp);
 
-	snd_ctl_add(sonic->card, snd_ctl_new1(&snd_sonicvibes_game_control, sonic));
+	err = snd_ctl_add(sonic->card,
+		snd_ctl_new1(&snd_sonicvibes_game_control, sonic));
+	if (err < 0)
+		return err;
 
 	return 0;
 }
@@ -1515,7 +1519,10 @@ static int snd_sonic_probe(struct pci_dev *pci,
 		return err;
 	}
 
-	snd_sonicvibes_create_gameport(sonic);
+	if ((err = snd_sonicvibes_create_gameport(sonic)) < 0) {
+		snd_card_free(card);
+		return err;
+        }
 
 	if ((err = snd_card_register(card)) < 0) {
 		snd_card_free(card);
-- 
2.7.4


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

* Re: [PATCH v2] ALSA: sonicvibes: add error handling for snd_ctl_add
  2018-06-14 11:22 ` [PATCH v2] " Zhouyang Jia
@ 2018-06-14 11:30   ` Takashi Iwai
  0 siblings, 0 replies; 6+ messages in thread
From: Takashi Iwai @ 2018-06-14 11:30 UTC (permalink / raw)
  To: Zhouyang Jia; +Cc: alsa-devel, Bhumika Goyal, Jaroslav Kysela, linux-kernel

On Thu, 14 Jun 2018 13:22:18 +0200,
Zhouyang Jia 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.
> 
> Signed-off-by: Zhouyang Jia <jiazhouyang09@gmail.com>
> ---
> v1->v2:
> - Check the return value of snd_sonicvibes_create_gameport.
> ---
>  sound/pci/sonicvibes.c | 11 +++++++++--
>  1 file changed, 9 insertions(+), 2 deletions(-)
> 
> diff --git a/sound/pci/sonicvibes.c b/sound/pci/sonicvibes.c
> index a8abb15..75225b04 100644
> --- a/sound/pci/sonicvibes.c
> +++ b/sound/pci/sonicvibes.c
> @@ -1188,6 +1188,7 @@ SONICVIBES_SINGLE("Joystick Speed", 0, SV_IREG_GAME_PORT, 1, 15, 0);
>  static int snd_sonicvibes_create_gameport(struct sonicvibes *sonic)
>  {
>  	struct gameport *gp;
> +	int err;
>  
>  	sonic->gameport = gp = gameport_allocate_port();
>  	if (!gp) {
> @@ -1203,7 +1204,10 @@ static int snd_sonicvibes_create_gameport(struct sonicvibes *sonic)
>  
>  	gameport_register_port(gp);
>  
> -	snd_ctl_add(sonic->card, snd_ctl_new1(&snd_sonicvibes_game_control, sonic));
> +	err = snd_ctl_add(sonic->card,
> +		snd_ctl_new1(&snd_sonicvibes_game_control, sonic));
> +	if (err < 0)
> +		return err;
>  
>  	return 0;
>  }
> @@ -1515,7 +1519,10 @@ static int snd_sonic_probe(struct pci_dev *pci,
>  		return err;
>  	}
>  
> -	snd_sonicvibes_create_gameport(sonic);
> +	if ((err = snd_sonicvibes_create_gameport(sonic)) < 0) {
> +		snd_card_free(card);
> +		return err;
> +        }

You don't need to inherit the old-fashioned style "if ((err = xxx)"
in a new code.  Check what checkpatch.pl complains.


thanks,

Takashi

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

* [PATCH v3] ALSA: sonicvibes: add error handling for snd_ctl_add
  2018-06-11  8:08 [PATCH] ALSA: sonicvibes: add error handling for snd_ctl_add Zhouyang Jia
  2018-06-11 13:26 ` Takashi Iwai
  2018-06-14 11:22 ` [PATCH v2] " Zhouyang Jia
@ 2018-06-14 11:41 ` Zhouyang Jia
  2018-06-14 16:00   ` Takashi Iwai
  2 siblings, 1 reply; 6+ messages in thread
From: Zhouyang Jia @ 2018-06-14 11:41 UTC (permalink / raw)
  Cc: Zhouyang Jia, Jaroslav Kysela, Takashi Iwai, 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>
---
v1->v2:
- Check the return value of snd_sonicvibes_create_gameport.
v2->v3:
- Fix the code style.
---
 sound/pci/sonicvibes.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/sound/pci/sonicvibes.c b/sound/pci/sonicvibes.c
index a8abb15..7fbdb70 100644
--- a/sound/pci/sonicvibes.c
+++ b/sound/pci/sonicvibes.c
@@ -1188,6 +1188,7 @@ SONICVIBES_SINGLE("Joystick Speed", 0, SV_IREG_GAME_PORT, 1, 15, 0);
 static int snd_sonicvibes_create_gameport(struct sonicvibes *sonic)
 {
 	struct gameport *gp;
+	int err;
 
 	sonic->gameport = gp = gameport_allocate_port();
 	if (!gp) {
@@ -1203,7 +1204,10 @@ static int snd_sonicvibes_create_gameport(struct sonicvibes *sonic)
 
 	gameport_register_port(gp);
 
-	snd_ctl_add(sonic->card, snd_ctl_new1(&snd_sonicvibes_game_control, sonic));
+	err = snd_ctl_add(sonic->card,
+		snd_ctl_new1(&snd_sonicvibes_game_control, sonic));
+	if (err < 0)
+		return err;
 
 	return 0;
 }
@@ -1515,7 +1519,11 @@ static int snd_sonic_probe(struct pci_dev *pci,
 		return err;
 	}
 
-	snd_sonicvibes_create_gameport(sonic);
+	err = snd_sonicvibes_create_gameport(sonic);
+	if (err < 0) {
+		snd_card_free(card);
+		return err;
+	}
 
 	if ((err = snd_card_register(card)) < 0) {
 		snd_card_free(card);
-- 
2.7.4


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

* Re: [PATCH v3] ALSA: sonicvibes: add error handling for snd_ctl_add
  2018-06-14 11:41 ` [PATCH v3] " Zhouyang Jia
@ 2018-06-14 16:00   ` Takashi Iwai
  0 siblings, 0 replies; 6+ messages in thread
From: Takashi Iwai @ 2018-06-14 16:00 UTC (permalink / raw)
  To: Zhouyang Jia; +Cc: alsa-devel, Bhumika Goyal, Jaroslav Kysela, linux-kernel

On Thu, 14 Jun 2018 13:41:37 +0200,
Zhouyang Jia 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.
> 
> Signed-off-by: Zhouyang Jia <jiazhouyang09@gmail.com>
> ---
> v1->v2:
> - Check the return value of snd_sonicvibes_create_gameport.
> v2->v3:
> - Fix the code style.

Applied, thanks.


Takashi

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

end of thread, other threads:[~2018-06-14 16:00 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-06-11  8:08 [PATCH] ALSA: sonicvibes: add error handling for snd_ctl_add Zhouyang Jia
2018-06-11 13:26 ` Takashi Iwai
2018-06-14 11:22 ` [PATCH v2] " Zhouyang Jia
2018-06-14 11:30   ` Takashi Iwai
2018-06-14 11:41 ` [PATCH v3] " Zhouyang Jia
2018-06-14 16:00   ` Takashi Iwai

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).