ALSA: ctxfi: Use common error handling code in two functions
authorMarkus Elfring <elfring@users.sourceforge.net>
Tue, 22 Aug 2017 16:43:42 +0000 (18:43 +0200)
committerTakashi Iwai <tiwai@suse.de>
Tue, 22 Aug 2017 17:43:29 +0000 (19:43 +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>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
sound/pci/ctxfi/ctpcm.c

index 358f5206130a3746dee1c50cb6cebeda4bef9d55..b36e37ae2b519b64bdf24e0b2ff9dd8ce11375f9 100644 (file)
@@ -140,27 +140,28 @@ static int ct_pcm_playback_open(struct snd_pcm_substream *substream)
 
        err = snd_pcm_hw_constraint_integer(runtime,
                                            SNDRV_PCM_HW_PARAM_PERIODS);
-       if (err < 0) {
-               kfree(apcm);
-               return err;
-       }
+       if (err < 0)
+               goto free_pcm;
+
        err = snd_pcm_hw_constraint_minmax(runtime,
                                           SNDRV_PCM_HW_PARAM_BUFFER_BYTES,
                                           1024, UINT_MAX);
-       if (err < 0) {
-               kfree(apcm);
-               return err;
-       }
+       if (err < 0)
+               goto free_pcm;
 
        apcm->timer = ct_timer_instance_new(atc->timer, apcm);
        if (!apcm->timer) {
-               kfree(apcm);
-               return -ENOMEM;
+               err = -ENOMEM;
+               goto free_pcm;
        }
        runtime->private_data = apcm;
        runtime->private_free = ct_atc_pcm_free_substream;
 
        return 0;
+
+free_pcm:
+       kfree(apcm);
+       return err;
 }
 
 static int ct_pcm_playback_close(struct snd_pcm_substream *substream)
@@ -286,27 +287,28 @@ static int ct_pcm_capture_open(struct snd_pcm_substream *substream)
 
        err = snd_pcm_hw_constraint_integer(runtime,
                                            SNDRV_PCM_HW_PARAM_PERIODS);
-       if (err < 0) {
-               kfree(apcm);
-               return err;
-       }
+       if (err < 0)
+               goto free_pcm;
+
        err = snd_pcm_hw_constraint_minmax(runtime,
                                           SNDRV_PCM_HW_PARAM_BUFFER_BYTES,
                                           1024, UINT_MAX);
-       if (err < 0) {
-               kfree(apcm);
-               return err;
-       }
+       if (err < 0)
+               goto free_pcm;
 
        apcm->timer = ct_timer_instance_new(atc->timer, apcm);
        if (!apcm->timer) {
-               kfree(apcm);
-               return -ENOMEM;
+               err = -ENOMEM;
+               goto free_pcm;
        }
        runtime->private_data = apcm;
        runtime->private_free = ct_atc_pcm_free_substream;
 
        return 0;
+
+free_pcm:
+       kfree(apcm);
+       return err;
 }
 
 static int ct_pcm_capture_close(struct snd_pcm_substream *substream)