sound: Fix esoteric double free in the dummy sound driver.
[pandora-kernel.git] / sound / drivers / dummy.c
index 83ac498..4f900d8 100644 (file)
@@ -230,13 +230,14 @@ static int snd_card_dummy_pcm_prepare(struct snd_pcm_substream *substream)
 {
        struct snd_pcm_runtime *runtime = substream->runtime;
        struct snd_dummy_pcm *dpcm = runtime->private_data;
-       unsigned int bps;
+       int bps;
+
+       bps = snd_pcm_format_width(runtime->format) * runtime->rate *
+               runtime->channels / 8;
 
-       bps = runtime->rate * runtime->channels;
-       bps *= snd_pcm_format_width(runtime->format);
-       bps /= 8;
        if (bps <= 0)
                return -EINVAL;
+
        dpcm->pcm_bps = bps;
        dpcm->pcm_hz = HZ;
        dpcm->pcm_buffer_size = snd_pcm_lib_buffer_bytes(substream);
@@ -353,6 +354,7 @@ static int snd_card_dummy_playback_open(struct snd_pcm_substream *substream)
        if ((dpcm = new_pcm_stream(substream)) == NULL)
                return -ENOMEM;
        runtime->private_data = dpcm;
+       /* makes the infrastructure responsible for freeing dpcm */
        runtime->private_free = snd_card_dummy_runtime_free;
        runtime->hw = snd_card_dummy_playback;
        if (substream->pcm->device & 1) {
@@ -361,10 +363,8 @@ static int snd_card_dummy_playback_open(struct snd_pcm_substream *substream)
        }
        if (substream->pcm->device & 2)
                runtime->hw.info &= ~(SNDRV_PCM_INFO_MMAP|SNDRV_PCM_INFO_MMAP_VALID);
-       if ((err = add_playback_constraints(runtime)) < 0) {
-               kfree(dpcm);
+       if ((err = add_playback_constraints(runtime)) < 0)
                return err;
-       }
 
        return 0;
 }
@@ -378,6 +378,7 @@ static int snd_card_dummy_capture_open(struct snd_pcm_substream *substream)
        if ((dpcm = new_pcm_stream(substream)) == NULL)
                return -ENOMEM;
        runtime->private_data = dpcm;
+       /* makes the infrastructure responsible for freeing dpcm */
        runtime->private_free = snd_card_dummy_runtime_free;
        runtime->hw = snd_card_dummy_capture;
        if (substream->pcm->device == 1) {
@@ -386,10 +387,8 @@ static int snd_card_dummy_capture_open(struct snd_pcm_substream *substream)
        }
        if (substream->pcm->device & 2)
                runtime->hw.info &= ~(SNDRV_PCM_INFO_MMAP|SNDRV_PCM_INFO_MMAP_VALID);
-       if ((err = add_capture_constraints(runtime)) < 0) {
-               kfree(dpcm);
+       if ((err = add_capture_constraints(runtime)) < 0)
                return err;
-       }
 
        return 0;
 }
@@ -564,7 +563,8 @@ static int __devinit snd_card_dummy_new_mixer(struct snd_dummy *dummy)
        unsigned int idx;
        int err;
 
-       snd_assert(dummy != NULL, return -EINVAL);
+       if (snd_BUG_ON(!dummy))
+               return -EINVAL;
        spin_lock_init(&dummy->mixer_lock);
        strcpy(card->mixername, "Dummy Mixer");