Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1718146

[PATCH 1/6] ALSA: pcm: Use common error handling code in _snd_pcm_new()

From SF Markus Elfring <elfring@users.sourceforge.net>
Newsgroups linux.kernel
Subject [PATCH 1/6] ALSA: pcm: Use common error handling code in _snd_pcm_new()
Date 2017-08-23 10:30 +0200
Message-ID <uhzd0-6Ct-37@gated-at.bofh.it> (permalink)
References <uhmSw-6HP-59@gated-at.bofh.it> <uhwf7-4Nc-1@gated-at.bofh.it> <uhzd0-6Ct-25@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


From: Markus Elfring <elfring@users.sourceforge.net>
Date: Wed, 23 Aug 2017 08:40:37 +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>
---
 sound/core/pcm.c | 30 ++++++++++++++++++------------
 1 file changed, 18 insertions(+), 12 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;
 }
 
 /**
-- 
2.14.0

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH] ALSA: core: Use common error handling code in two functions SF Markus Elfring <elfring@users.sourceforge.net> - 2017-08-22 21:20 +0200
  Re: [PATCH] ALSA: core: Use common error handling code in two functions Takashi Iwai <tiwai@suse.de> - 2017-08-23 07:20 +0200
    [PATCH 0/6] ALSA: core: Fine-tuning for some function implementations SF Markus Elfring <elfring@users.sourceforge.net> - 2017-08-23 10:30 +0200
      [PATCH 3/6] ALSA: pcm: Adjust 11 checks for null pointers SF Markus Elfring <elfring@users.sourceforge.net> - 2017-08-23 10:30 +0200
        Re: [PATCH 3/6] ALSA: pcm: Adjust 11 checks for null pointers Takashi Iwai <tiwai@suse.de> - 2017-08-23 10:40 +0200
      [PATCH 2/6] ALSA: pcm: Adjust nine function calls together with a  variable assignment SF Markus Elfring <elfring@users.sourceforge.net> - 2017-08-23 10:30 +0200
        Re: [PATCH 2/6] ALSA: pcm: Adjust nine function calls together with a variable assignment Takashi Iwai <tiwai@suse.de> - 2017-08-23 10:40 +0200
      [PATCH 1/6] ALSA: pcm: Use common error handling code in  _snd_pcm_new() SF Markus Elfring <elfring@users.sourceforge.net> - 2017-08-23 10:30 +0200
        Re: [PATCH 1/6] ALSA: pcm: Use common error handling code in _snd_pcm_new() Takashi Iwai <tiwai@suse.de> - 2017-08-23 10:40 +0200
      [PATCH 4/6] ALSA: timer: Use common error handling code in  alsa_timer_init() SF Markus Elfring <elfring@users.sourceforge.net> - 2017-08-23 10:30 +0200
        Re: [PATCH 4/6] ALSA: timer: Use common error handling code in alsa_timer_init() Takashi Iwai <tiwai@suse.de> - 2017-08-23 10:40 +0200
      [PATCH 5/6] ALSA: timer: Adjust a condition check in  snd_timer_resolution() SF Markus Elfring <elfring@users.sourceforge.net> - 2017-08-23 10:30 +0200
        Re: [PATCH 5/6] ALSA: timer: Adjust a condition check in snd_timer_resolution() Takashi Iwai <tiwai@suse.de> - 2017-08-23 10:40 +0200
      [PATCH 6/6] ALSA: timer: Adjust 13 checks for null pointers SF Markus Elfring <elfring@users.sourceforge.net> - 2017-08-23 10:40 +0200
        Re: [PATCH 6/6] ALSA: timer: Adjust 13 checks for null pointers Takashi Iwai <tiwai@suse.de> - 2017-08-23 10:40 +0200

csiph-web