public inbox for kernel-janitors@vger.kernel.org
 help / color / mirror / Atom feed
From: SF Markus Elfring <elfring@users.sourceforge.net>
To: alsa-devel@alsa-project.org, Arnd Bergmann <arnd@arndb.de>,
	Arvind Yadav <arvind.yadav.cs@gmail.com>,
	Dan Carpenter <dan.carpenter@oracle.com>,
	Ingo Molnar <mingo@kernel.org>, Jaroslav Kysela <perex@perex.cz>,
	Takashi Iwai <tiwai@suse.com>,
	Takashi Sakamoto <o-takashi@sakamocchi.jp>,
	Vegard Nossum <vegard.nossum@oracle.com>
Cc: kernel-janitors@vger.kernel.org, LKML <linux-kernel@vger.kernel.org>
Subject: [PATCH] ALSA: core: Use common error handling code in two functions
Date: Tue, 22 Aug 2017 19:12:02 +0000	[thread overview]
Message-ID: <b8c9e41b-a47e-1d99-3d1a-5d39772e4b54@users.sourceforge.net> (raw)

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

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/core/pcm.c   | 30 ++++++++++++++++++------------
 sound/core/timer.c | 10 ++++++----
 2 files changed, 24 insertions(+), 16 deletions(-)

diff --git a/sound/core/pcm.c b/sound/core/pcm.c
index 89c7485519cb..048df9658f50 100644
--- a/sound/core/pcm.c
+++ b/sound/core/pcm.c
@@ -783,21 +783,27 @@ static int _snd_pcm_new(struct snd_card *card, const char *id, int device,
 	INIT_LIST_HEAD(&pcm->list);
 	if (id)
 		strlcpy(pcm->id, id, sizeof(pcm->id));
-	if ((err = snd_pcm_new_stream(pcm, SNDRV_PCM_STREAM_PLAYBACK, playback_count)) < 0) {
-		snd_pcm_free(pcm);
-		return err;
-	}
-	if ((err = snd_pcm_new_stream(pcm, SNDRV_PCM_STREAM_CAPTURE, capture_count)) < 0) {
-		snd_pcm_free(pcm);
-		return err;
-	}
-	if ((err = snd_device_new(card, SNDRV_DEV_PCM, pcm, &ops)) < 0) {
-		snd_pcm_free(pcm);
-		return err;
-	}
+
+	err = snd_pcm_new_stream(pcm, SNDRV_PCM_STREAM_PLAYBACK,
+				 playback_count);
+	if (err < 0)
+		goto free_pcm;
+
+	err = snd_pcm_new_stream(pcm, SNDRV_PCM_STREAM_CAPTURE, capture_count);
+	if (err < 0)
+		goto free_pcm;
+
+	err = snd_device_new(card, SNDRV_DEV_PCM, pcm, &ops);
+	if (err < 0)
+		goto free_pcm;
+
 	if (rpcm)
 		*rpcm = pcm;
 	return 0;
+
+free_pcm:
+	snd_pcm_free(pcm);
+	return err;
 }
 
 /**
diff --git a/sound/core/timer.c b/sound/core/timer.c
index a9b9a277e00c..6d73a63f6e2b 100644
--- a/sound/core/timer.c
+++ b/sound/core/timer.c
@@ -2096,8 +2096,7 @@ static int __init alsa_timer_init(void)
 	err = snd_timer_register_system();
 	if (err < 0) {
 		pr_err("ALSA: unable to register system timer (%i)\n", err);
-		put_device(&timer_dev);
-		return err;
+		goto put_timer;
 	}
 
 	err = snd_register_device(SNDRV_DEVICE_TYPE_TIMER, NULL, 0,
@@ -2105,12 +2104,15 @@ static int __init alsa_timer_init(void)
 	if (err < 0) {
 		pr_err("ALSA: unable to register timer device (%i)\n", err);
 		snd_timer_free_all();
-		put_device(&timer_dev);
-		return err;
+		goto put_timer;
 	}
 
 	snd_timer_proc_init();
 	return 0;
+
+put_timer:
+	put_device(&timer_dev);
+	return err;
 }
 
 static void __exit alsa_timer_exit(void)
-- 
2.14.0


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

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-22 19:12 SF Markus Elfring [this message]
2017-08-23  5:16 ` [PATCH] ALSA: core: Use common error handling code in two functions Takashi Iwai
2017-08-23  8:21   ` [PATCH 0/6] ALSA: core: Fine-tuning for some function implementations SF Markus Elfring
2017-08-23  8:23     ` [PATCH 1/6] ALSA: pcm: Use common error handling code in _snd_pcm_new() SF Markus Elfring
2017-08-23  8:36       ` Takashi Iwai
2017-08-23  8:24     ` [PATCH 2/6] ALSA: pcm: Adjust nine function calls together with a variable assignment SF Markus Elfring
2017-08-23  8:36       ` Takashi Iwai
2017-08-23  8:25     ` [PATCH 3/6] ALSA: pcm: Adjust 11 checks for null pointers SF Markus Elfring
2017-08-23  8:35       ` Takashi Iwai
2017-08-23  8:27     ` [PATCH 4/6] ALSA: timer: Use common error handling code in alsa_timer_init() SF Markus Elfring
2017-08-23  8:39       ` Takashi Iwai
2017-08-23  8:28     ` [PATCH 5/6] ALSA: timer: Adjust a condition check in snd_timer_resolution() SF Markus Elfring
2017-08-23  8:37       ` Takashi Iwai
2017-08-23  8:29     ` [PATCH 6/6] ALSA: timer: Adjust 13 checks for null pointers SF Markus Elfring
2017-08-23  8:38       ` 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=b8c9e41b-a47e-1d99-3d1a-5d39772e4b54@users.sourceforge.net \
    --to=elfring@users.sourceforge.net \
    --cc=alsa-devel@alsa-project.org \
    --cc=arnd@arndb.de \
    --cc=arvind.yadav.cs@gmail.com \
    --cc=dan.carpenter@oracle.com \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=o-takashi@sakamocchi.jp \
    --cc=perex@perex.cz \
    --cc=tiwai@suse.com \
    --cc=vegard.nossum@oracle.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