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, Fabian Frederick <fabf@skynet.be>,
	Ingo Molnar <mingo@kernel.org>, Jaroslav Kysela <perex@perex.cz>,
	Takashi Iwai <tiwai@suse.com>,
	Takashi Sakamoto <o-takashi@sakamocchi.jp>
Cc: LKML <linux-kernel@vger.kernel.org>, kernel-janitors@vger.kernel.org
Subject: [PATCH 2/3] ALSA: rawmidi: Use common error handling code in snd_rawmidi_new()
Date: Sat, 11 Nov 2017 12:12:13 +0100	[thread overview]
Message-ID: <4f75ca87-05bb-d32c-0691-4b7d7a8ad3da@users.sourceforge.net> (raw)
In-Reply-To: <d4c89bda-5091-2d3c-ded1-ba2c3b061ff6@users.sourceforge.net>

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

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>
---
 sound/core/rawmidi.c | 23 +++++++++++------------
 1 file changed, 11 insertions(+), 12 deletions(-)

diff --git a/sound/core/rawmidi.c b/sound/core/rawmidi.c
index c17f173150e9..34686000ecce 100644
--- a/sound/core/rawmidi.c
+++ b/sound/core/rawmidi.c
@@ -1560,10 +1560,8 @@ int snd_rawmidi_new(struct snd_card *card, char *id, int device,
 					 ->streams[SNDRV_RAWMIDI_STREAM_INPUT],
 					 SNDRV_RAWMIDI_STREAM_INPUT,
 					 input_count);
-	if (err < 0) {
-		snd_rawmidi_free(rmidi);
-		return err;
-	}
+	if (err < 0)
+		goto free_midi;
 
 	err =
 	    snd_rawmidi_alloc_substreams(rmidi,
@@ -1571,19 +1569,20 @@ int snd_rawmidi_new(struct snd_card *card, char *id, int device,
 					 ->streams[SNDRV_RAWMIDI_STREAM_OUTPUT],
 					 SNDRV_RAWMIDI_STREAM_OUTPUT,
 					 output_count);
-	if (err < 0) {
-		snd_rawmidi_free(rmidi);
-		return err;
-	}
+	if (err < 0)
+		goto free_midi;
 
 	err = snd_device_new(card, SNDRV_DEV_RAWMIDI, rmidi, &ops);
-	if (err < 0) {
-		snd_rawmidi_free(rmidi);
-		return err;
-	}
+	if (err < 0)
+		goto free_midi;
+
 	if (rrawmidi)
 		*rrawmidi = rmidi;
 	return 0;
+
+free_midi:
+	snd_rawmidi_free(rmidi);
+	return err;
 }
 EXPORT_SYMBOL(snd_rawmidi_new);
 
-- 
2.15.0

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

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-11 11:10 [PATCH 0/3] ALSA: rawmidi: Adjustments for some function implementations SF Markus Elfring
2017-11-11 11:11 ` [PATCH 1/3] ALSA: rawmidi: Adjust seven function calls together with a variable assignment SF Markus Elfring
2017-11-11 11:12 ` SF Markus Elfring [this message]
2017-11-11 11:13 ` [PATCH 3/3] ALSA: rawmidi: Adjust 21 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=4f75ca87-05bb-d32c-0691-4b7d7a8ad3da@users.sourceforge.net \
    --to=elfring@users.sourceforge.net \
    --cc=alsa-devel@alsa-project.org \
    --cc=fabf@skynet.be \
    --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 \
    /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).