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>, Takashi Iwai <tiwai@suse.com>
Cc: LKML <linux-kernel@vger.kernel.org>, kernel-janitors@vger.kernel.org
Subject: [PATCH 1/3] ALSA: ml403-ac97cr: Use common error handling code in two functions
Date: Sat, 11 Nov 2017 14:17:18 +0100	[thread overview]
Message-ID: <c9e8516e-b5cb-97cf-e8b8-86ebdd1ca284@users.sourceforge.net> (raw)
In-Reply-To: <4c38a970-2407-3559-060d-501b8259b3fc@users.sourceforge.net>

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sat, 11 Nov 2017 13:50:24 +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/drivers/ml403-ac97cr.c | 52 ++++++++++++++++++++++----------------------
 1 file changed, 26 insertions(+), 26 deletions(-)

diff --git a/sound/drivers/ml403-ac97cr.c b/sound/drivers/ml403-ac97cr.c
index 18fd12996cf7..12a54bfde1a5 100644
--- a/sound/drivers/ml403-ac97cr.c
+++ b/sound/drivers/ml403-ac97cr.c
@@ -1144,8 +1144,7 @@ snd_ml403_ac97cr_create(struct snd_card *card, struct platform_device *pfdev,
 		snd_printk(KERN_ERR SND_ML403_AC97CR_DRIVER ": "
 			   "unable to remap memory region (%pR)\n",
 			   resource);
-		snd_ml403_ac97cr_free(ml403_ac97cr);
-		return -EBUSY;
+		goto e_busy;
 	}
 	snd_printk(KERN_INFO SND_ML403_AC97CR_DRIVER ": "
 		   "remap controller memory region to "
@@ -1157,8 +1156,7 @@ snd_ml403_ac97cr_create(struct snd_card *card, struct platform_device *pfdev,
 		snd_printk(KERN_ERR SND_ML403_AC97CR_DRIVER ": "
 			   "unable to grab IRQ %d\n",
 			   irq);
-		snd_ml403_ac97cr_free(ml403_ac97cr);
-		return -EBUSY;
+		goto e_busy;
 	}
 	ml403_ac97cr->irq = irq;
 	snd_printk(KERN_INFO SND_ML403_AC97CR_DRIVER ": "
@@ -1170,8 +1168,7 @@ snd_ml403_ac97cr_create(struct snd_card *card, struct platform_device *pfdev,
 		snd_printk(KERN_ERR SND_ML403_AC97CR_DRIVER ": "
 			   "unable to grab IRQ %d\n",
 			   irq);
-		snd_ml403_ac97cr_free(ml403_ac97cr);
-		return -EBUSY;
+		goto e_busy;
 	}
 	ml403_ac97cr->capture_irq = irq;
 	snd_printk(KERN_INFO SND_ML403_AC97CR_DRIVER ": "
@@ -1179,20 +1176,23 @@ snd_ml403_ac97cr_create(struct snd_card *card, struct platform_device *pfdev,
 		   ml403_ac97cr->capture_irq);
 
 	err = snd_ml403_ac97cr_chip_init(ml403_ac97cr);
-	if (err < 0) {
-		snd_ml403_ac97cr_free(ml403_ac97cr);
-		return err;
-	}
+	if (err < 0)
+		goto free_data;
 
 	err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, ml403_ac97cr, &ops);
 	if (err < 0) {
 		PDEBUG(INIT_FAILURE, "probe(): snd_device_new() failed!\n");
-		snd_ml403_ac97cr_free(ml403_ac97cr);
-		return err;
+		goto free_data;
 	}
 
 	*rml403_ac97cr = ml403_ac97cr;
 	return 0;
+
+e_busy:
+	err = -EBUSY;
+free_data:
+	snd_ml403_ac97cr_free(ml403_ac97cr);
+	return err;
 }
 
 static void snd_ml403_ac97cr_mixer_free(struct snd_ac97 *ac97)
@@ -1281,22 +1281,19 @@ static int snd_ml403_ac97cr_probe(struct platform_device *pfdev)
 	err = snd_ml403_ac97cr_create(card, pfdev, &ml403_ac97cr);
 	if (err < 0) {
 		PDEBUG(INIT_FAILURE, "probe(): create failed!\n");
-		snd_card_free(card);
-		return err;
+		goto free_card;
 	}
 	PDEBUG(INIT_INFO, "probe(): create done\n");
 	card->private_data = ml403_ac97cr;
 	err = snd_ml403_ac97cr_mixer(ml403_ac97cr);
-	if (err < 0) {
-		snd_card_free(card);
-		return err;
-	}
+	if (err < 0)
+		goto free_card;
+
 	PDEBUG(INIT_INFO, "probe(): mixer done\n");
 	err = snd_ml403_ac97cr_pcm(ml403_ac97cr, 0);
-	if (err < 0) {
-		snd_card_free(card);
-		return err;
-	}
+	if (err < 0)
+		goto free_card;
+
 	PDEBUG(INIT_INFO, "probe(): PCM done\n");
 	strcpy(card->driver, SND_ML403_AC97CR_DRIVER);
 	strcpy(card->shortname, "ML403 AC97 Controller Reference");
@@ -1306,13 +1303,16 @@ static int snd_ml403_ac97cr_probe(struct platform_device *pfdev)
 		ml403_ac97cr->capture_irq, dev + 1);
 
 	err = snd_card_register(card);
-	if (err < 0) {
-		snd_card_free(card);
-		return err;
-	}
+	if (err < 0)
+		goto free_card;
+
 	platform_set_drvdata(pfdev, card);
 	PDEBUG(INIT_INFO, "probe(): (done)\n");
 	return 0;
+
+free_card:
+	snd_card_free(card);
+	return err;
 }
 
 static int snd_ml403_ac97cr_remove(struct platform_device *pfdev)
-- 
2.15.0

  reply	other threads:[~2017-11-11 13:18 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-11 13:16 [PATCH 0/3] ALSA: ml403-ac97cr: Fine-tuning for five function implementations SF Markus Elfring
2017-11-11 13:17 ` SF Markus Elfring [this message]
2017-11-11 13:18 ` [PATCH 2/3] ALSA: ml403-ac97cr: Delete an unnecessary return statement in snd_ml403_ac97cr_codec_write() SF Markus Elfring
2017-11-11 13:19 ` [PATCH 3/3] ALSA: ml403-ac97cr: Adjust four checks for null pointers 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=c9e8516e-b5cb-97cf-e8b8-86ebdd1ca284@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=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).