public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: SF Markus Elfring <elfring@users.sourceforge.net>
To: alsa-devel@alsa-project.org,
	Dan Carpenter <dan.carpenter@oracle.com>,
	Jaroslav Kysela <perex@perex.cz>, Takashi Iwai <tiwai@suse.de>
Cc: kernel-janitors@vger.kernel.org, LKML <linux-kernel@vger.kernel.org>
Subject: [PATCH v3] ALSA: pcsp: Use common error handling code in snd_card_pcsp_probe()
Date: Tue, 22 Aug 2017 17:47:26 +0200	[thread overview]
Message-ID: <49a7aeef-ba4d-7962-83cc-60d90a5a02cf@users.sourceforge.net> (raw)
In-Reply-To: <s5hwp5v7i9h.wl-tiwai@suse.de>

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Tue, 22 Aug 2017 17:33:33 +0200

Add a jump target so that a bit of exception handling can be better reused
at the end of this function.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---

v3:
* An approach to make a few checks for a failure predicate a bit safer
  was rejected today.

* An extra blank line was added before a label.

v2:
Two statements were moved together with an additional jump label to the end
of this function.

 sound/drivers/pcsp/pcsp.c | 29 +++++++++++++----------------
 1 file changed, 13 insertions(+), 16 deletions(-)

diff --git a/sound/drivers/pcsp/pcsp.c b/sound/drivers/pcsp/pcsp.c
index 72e2d0012084..0dd3f46eb03e 100644
--- a/sound/drivers/pcsp/pcsp.c
+++ b/sound/drivers/pcsp/pcsp.c
@@ -108,22 +108,17 @@ static int snd_card_pcsp_probe(int devnum, struct device *dev)
 		return err;
 
 	err = snd_pcsp_create(card);
-	if (err < 0) {
-		snd_card_free(card);
-		return err;
-	}
+	if (err < 0)
+		goto free_card;
+
 	if (!nopcm) {
 		err = snd_pcsp_new_pcm(&pcsp_chip);
-		if (err < 0) {
-			snd_card_free(card);
-			return err;
-		}
+		if (err < 0)
+			goto free_card;
 	}
 	err = snd_pcsp_new_mixer(&pcsp_chip, nopcm);
-	if (err < 0) {
-		snd_card_free(card);
-		return err;
-	}
+	if (err < 0)
+		goto free_card;
 
 	strcpy(card->driver, "PC-Speaker");
 	strcpy(card->shortname, "pcsp");
@@ -131,12 +126,14 @@ static int snd_card_pcsp_probe(int devnum, struct device *dev)
 		pcsp_chip.port);
 
 	err = snd_card_register(card);
-	if (err < 0) {
-		snd_card_free(card);
-		return err;
-	}
+	if (err < 0)
+		goto free_card;
 
 	return 0;
+
+free_card:
+	snd_card_free(card);
+	return err;
 }
 
 static int alsa_card_pcsp_init(struct device *dev)
-- 
2.14.0

  reply	other threads:[~2017-08-22 15:48 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-22 12:10 [PATCH] ALSA: pcsp: Use common error handling code in snd_card_pcsp_probe() SF Markus Elfring
2017-08-22 12:16 ` Dan Carpenter
2017-08-22 12:28   ` Takashi Iwai
2017-08-22 12:47     ` SF Markus Elfring
2017-08-22 12:55       ` [alsa-devel] " Takashi Iwai
2017-08-22 13:15         ` SF Markus Elfring
2017-08-22 14:07           ` Takashi Iwai
2017-08-22 14:36             ` SF Markus Elfring
2017-08-22 14:49               ` Takashi Iwai
2017-08-22 15:03                 ` SF Markus Elfring
2017-08-22 15:07                   ` Takashi Iwai
2017-08-22 15:47                     ` SF Markus Elfring [this message]
2017-08-22 15:59                       ` [PATCH v3] " Takashi Iwai
2017-08-22 14:00     ` [PATCH v2] " SF Markus Elfring

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=49a7aeef-ba4d-7962-83cc-60d90a5a02cf@users.sourceforge.net \
    --to=elfring@users.sourceforge.net \
    --cc=alsa-devel@alsa-project.org \
    --cc=dan.carpenter@oracle.com \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=perex@perex.cz \
    --cc=tiwai@suse.de \
    /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