From: Zhouyang Jia <jiazhouyang09@gmail.com>
To: unlisted-recipients:; (no To-header on input)
Cc: Zhouyang Jia <jiazhouyang09@gmail.com>,
Jaroslav Kysela <perex@perex.cz>, Takashi Iwai <tiwai@suse.com>,
Bhumika Goyal <bhumirks@gmail.com>,
alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org
Subject: [PATCH v3] ALSA: sonicvibes: add error handling for snd_ctl_add
Date: Thu, 14 Jun 2018 19:41:37 +0800 [thread overview]
Message-ID: <1528976499-52071-1-git-send-email-jiazhouyang09@gmail.com> (raw)
In-Reply-To: <1528704521-34060-1-git-send-email-jiazhouyang09@gmail.com>
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
next prev parent reply other threads:[~2018-06-14 11:41 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
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 ` Zhouyang Jia [this message]
2018-06-14 16:00 ` [PATCH v3] " Takashi Iwai
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1528976499-52071-1-git-send-email-jiazhouyang09@gmail.com \
--to=jiazhouyang09@gmail.com \
--cc=alsa-devel@alsa-project.org \
--cc=bhumirks@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=perex@perex.cz \
--cc=tiwai@suse.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).