linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: SF Markus Elfring <elfring@users.sourceforge.net>
To: alsa-devel@alsa-project.org,
	Arvind Yadav <arvind.yadav.cs@gmail.com>,
	Bhumika Goyal <bhumirks@gmail.com>,
	Jaroslav Kysela <perex@perex.cz>, Mark Brown <broonie@kernel.org>,
	Takashi Iwai <tiwai@suse.com>
Cc: LKML <linux-kernel@vger.kernel.org>, kernel-janitors@vger.kernel.org
Subject: [PATCH 1/3] ALSA: sgio2audio: Use common error handling code in two functions
Date: Sat, 11 Nov 2017 20:21:41 +0100	[thread overview]
Message-ID: <7d824a50-4333-a0d5-6a64-3c28f87b12e0@users.sourceforge.net> (raw)
In-Reply-To: <eb375101-03bd-37bb-67ef-e261eeca206e@users.sourceforge.net>

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sat, 11 Nov 2017 19:56:07 +0100

Add jump targets so that a bit of exception handling can be better reused
at the end of these functions.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 sound/mips/sgio2audio.c | 47 +++++++++++++++++++++++------------------------
 1 file changed, 23 insertions(+), 24 deletions(-)

diff --git a/sound/mips/sgio2audio.c b/sound/mips/sgio2audio.c
index 71c942162c25..62715a01f507 100644
--- a/sound/mips/sgio2audio.c
+++ b/sound/mips/sgio2audio.c
@@ -893,18 +893,19 @@ static int snd_sgio2audio_create(struct snd_card *card,
 
 	/* initialize the AD1843 codec */
 	err = ad1843_init(&chip->ad1843);
-	if (err < 0) {
-		snd_sgio2audio_free(chip);
-		return err;
-	}
+	if (err < 0)
+		goto free_chip;
 
 	err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops);
-	if (err < 0) {
-		snd_sgio2audio_free(chip);
-		return err;
-	}
+	if (err < 0)
+		goto free_chip;
+
 	*rchip = chip;
 	return 0;
+
+free_chip:
+	snd_sgio2audio_free(chip);
+	return err;
 }
 
 static int snd_sgio2audio_probe(struct platform_device *pdev)
@@ -918,21 +919,16 @@ static int snd_sgio2audio_probe(struct platform_device *pdev)
 		return err;
 
 	err = snd_sgio2audio_create(card, &chip);
-	if (err < 0) {
-		snd_card_free(card);
-		return err;
-	}
+	if (err < 0)
+		goto free_card;
 
 	err = snd_sgio2audio_new_pcm(chip);
-	if (err < 0) {
-		snd_card_free(card);
-		return err;
-	}
+	if (err < 0)
+		goto free_card;
+
 	err = snd_sgio2audio_new_mixer(chip);
-	if (err < 0) {
-		snd_card_free(card);
-		return err;
-	}
+	if (err < 0)
+		goto free_card;
 
 	strcpy(card->driver, "SGI O2 Audio");
 	strcpy(card->shortname, "SGI O2 Audio");
@@ -942,12 +938,15 @@ static int snd_sgio2audio_probe(struct platform_device *pdev)
 		MACEISA_AUDIO3_MERR_IRQ);
 
 	err = snd_card_register(card);
-	if (err < 0) {
-		snd_card_free(card);
-		return err;
-	}
+	if (err < 0)
+		goto free_card;
+
 	platform_set_drvdata(pdev, card);
 	return 0;
+
+free_card:
+	snd_card_free(card);
+	return err;
 }
 
 static int snd_sgio2audio_remove(struct platform_device *pdev)
-- 
2.15.0

  reply	other threads:[~2017-11-11 19:22 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-11 19:20 [PATCH 0/3] ALSA: sgio2audio: Fine-tuning for two function implementations SF Markus Elfring
2017-11-11 19:21 ` SF Markus Elfring [this message]
2017-11-11 19:22 ` [PATCH 2/3] ALSA: sgio2audio: Improve a size determination in snd_sgio2audio_create() SF Markus Elfring
2017-11-28  6:50   ` Takashi Iwai
2017-11-11 19:23 ` [PATCH 3/3] ALSA: sgio2audio: Adjust two null pointer checks " 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=7d824a50-4333-a0d5-6a64-3c28f87b12e0@users.sourceforge.net \
    --to=elfring@users.sourceforge.net \
    --cc=alsa-devel@alsa-project.org \
    --cc=arvind.yadav.cs@gmail.com \
    --cc=bhumirks@gmail.com \
    --cc=broonie@kernel.org \
    --cc=kernel-janitors@vger.kernel.org \
    --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).