ALSA: ymfpci: fix PCM open error handling
authorClemens Ladisch <clemens@ladisch.de>
Fri, 16 Sep 2011 20:52:48 +0000 (22:52 +0200)
committerTakashi Iwai <tiwai@suse.de>
Tue, 20 Sep 2011 06:56:34 +0000 (08:56 +0200)
The installation of the minimum period size constraint in the PCM open
callbacks was not checked for errors.  Add this check, and move the call
to the beginning of the function to avoid having to do any cleanups in
the error case.

Signed-off-by: Clemens Ladisch <clemens@ladisch.de>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
sound/pci/ymfpci/ymfpci_main.c

index ebfbb28..88c5c5c 100644 (file)
@@ -897,6 +897,15 @@ static int snd_ymfpci_playback_open_1(struct snd_pcm_substream *substream)
        struct snd_ymfpci *chip = snd_pcm_substream_chip(substream);
        struct snd_pcm_runtime *runtime = substream->runtime;
        struct snd_ymfpci_pcm *ypcm;
+       int err;
+
+       runtime->hw = snd_ymfpci_playback;
+       /* FIXME? True value is 256/48 = 5.33333 ms */
+       err = snd_pcm_hw_constraint_minmax(runtime,
+                                          SNDRV_PCM_HW_PARAM_PERIOD_TIME,
+                                          5334, UINT_MAX);
+       if (err < 0)
+               return err;
 
        ypcm = kzalloc(sizeof(*ypcm), GFP_KERNEL);
        if (ypcm == NULL)
@@ -904,11 +913,8 @@ static int snd_ymfpci_playback_open_1(struct snd_pcm_substream *substream)
        ypcm->chip = chip;
        ypcm->type = PLAYBACK_VOICE;
        ypcm->substream = substream;
-       runtime->hw = snd_ymfpci_playback;
        runtime->private_data = ypcm;
        runtime->private_free = snd_ymfpci_pcm_free_substream;
-       /* FIXME? True value is 256/48 = 5.33333 ms */
-       snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_PERIOD_TIME, 5333, UINT_MAX);
        return 0;
 }
 
@@ -1013,6 +1019,15 @@ static int snd_ymfpci_capture_open(struct snd_pcm_substream *substream,
        struct snd_ymfpci *chip = snd_pcm_substream_chip(substream);
        struct snd_pcm_runtime *runtime = substream->runtime;
        struct snd_ymfpci_pcm *ypcm;
+       int err;
+
+       runtime->hw = snd_ymfpci_capture;
+       /* FIXME? True value is 256/48 = 5.33333 ms */
+       err = snd_pcm_hw_constraint_minmax(runtime,
+                                          SNDRV_PCM_HW_PARAM_PERIOD_TIME,
+                                          5334, UINT_MAX);
+       if (err < 0)
+               return err;
 
        ypcm = kzalloc(sizeof(*ypcm), GFP_KERNEL);
        if (ypcm == NULL)
@@ -1022,9 +1037,6 @@ static int snd_ymfpci_capture_open(struct snd_pcm_substream *substream,
        ypcm->substream = substream;    
        ypcm->capture_bank_number = capture_bank_number;
        chip->capture_substream[capture_bank_number] = substream;
-       runtime->hw = snd_ymfpci_capture;
-       /* FIXME? True value is 256/48 = 5.33333 ms */
-       snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_PERIOD_TIME, 5333, UINT_MAX);
        runtime->private_data = ypcm;
        runtime->private_free = snd_ymfpci_pcm_free_substream;
        snd_ymfpci_hw_start(chip);