saa7134-alsa: Only frees registered sound cards
[pandora-kernel.git] / drivers / media / video / saa7134 / saa7134-alsa.c
index d3bd82a..11b0ef3 100644 (file)
@@ -172,7 +172,9 @@ static void saa7134_irq_alsa_done(struct saa7134_dev *dev,
                dprintk("irq: overrun [full=%d/%d] - Blocks in %d\n",dev->dmasound.read_count,
                        dev->dmasound.bufsize, dev->dmasound.blocks);
                spin_unlock(&dev->slock);
+               snd_pcm_stream_lock(dev->dmasound.substream);
                snd_pcm_stop(dev->dmasound.substream,SNDRV_PCM_STATE_XRUN);
+               snd_pcm_stream_unlock(dev->dmasound.substream);
                return;
        }
 
@@ -630,7 +632,7 @@ static int snd_card_saa7134_hw_params(struct snd_pcm_substream * substream,
        /* release the old buffer */
        if (substream->runtime->dma_area) {
                saa7134_pgtable_free(dev->pci, &dev->dmasound.pt);
-               videobuf_sg_dma_unmap(&dev->pci->dev, &dev->dmasound.dma);
+               videobuf_dma_unmap(&dev->pci->dev, &dev->dmasound.dma);
                dsp_buffer_free(dev);
                substream->runtime->dma_area = NULL;
        }
@@ -646,12 +648,12 @@ static int snd_card_saa7134_hw_params(struct snd_pcm_substream * substream,
                return err;
        }
 
-       if (0 != (err = videobuf_sg_dma_map(&dev->pci->dev, &dev->dmasound.dma))) {
+       if (0 != (err = videobuf_dma_map(&dev->pci->dev, &dev->dmasound.dma))) {
                dsp_buffer_free(dev);
                return err;
        }
        if (0 != (err = saa7134_pgtable_alloc(dev->pci,&dev->dmasound.pt))) {
-               videobuf_sg_dma_unmap(&dev->pci->dev, &dev->dmasound.dma);
+               videobuf_dma_unmap(&dev->pci->dev, &dev->dmasound.dma);
                dsp_buffer_free(dev);
                return err;
        }
@@ -660,7 +662,7 @@ static int snd_card_saa7134_hw_params(struct snd_pcm_substream * substream,
                                                dev->dmasound.dma.sglen,
                                                0))) {
                saa7134_pgtable_free(dev->pci, &dev->dmasound.pt);
-               videobuf_sg_dma_unmap(&dev->pci->dev, &dev->dmasound.dma);
+               videobuf_dma_unmap(&dev->pci->dev, &dev->dmasound.dma);
                dsp_buffer_free(dev);
                return err;
        }
@@ -669,7 +671,7 @@ static int snd_card_saa7134_hw_params(struct snd_pcm_substream * substream,
           byte, but it doesn't work. So I allocate the DMA using the
           V4L functions, and force ALSA to use that as the DMA area */
 
-       substream->runtime->dma_area = dev->dmasound.dma.vmalloc;
+       substream->runtime->dma_area = dev->dmasound.dma.vaddr;
        substream->runtime->dma_bytes = dev->dmasound.bufsize;
        substream->runtime->dma_addr = 0;
 
@@ -696,7 +698,7 @@ static int snd_card_saa7134_hw_free(struct snd_pcm_substream * substream)
 
        if (substream->runtime->dma_area) {
                saa7134_pgtable_free(dev->pci, &dev->dmasound.pt);
-               videobuf_sg_dma_unmap(&dev->pci->dev, &dev->dmasound.dma);
+               videobuf_dma_unmap(&dev->pci->dev, &dev->dmasound.dma);
                dsp_buffer_free(dev);
                substream->runtime->dma_area = NULL;
        }
@@ -1080,7 +1082,7 @@ static int alsa_card_saa7134_create(struct saa7134_dev *dev, int devnum)
        /* Card "creation" */
 
        card->private_free = snd_saa7134_free;
-       chip = (snd_card_saa7134_t *) card->private_data;
+       chip = card->private_data;
 
        spin_lock_init(&chip->lock);
        spin_lock_init(&chip->mixer_lock);
@@ -1143,6 +1145,8 @@ static int alsa_device_init(struct saa7134_dev *dev)
 
 static int alsa_device_exit(struct saa7134_dev *dev)
 {
+       if (!snd_saa7134_cards[dev->nr])
+               return 1;
 
        snd_card_free(snd_saa7134_cards[dev->nr]);
        snd_saa7134_cards[dev->nr] = NULL;
@@ -1192,7 +1196,8 @@ static void saa7134_alsa_exit(void)
        int idx;
 
        for (idx = 0; idx < SNDRV_CARDS; idx++) {
-               snd_card_free(snd_saa7134_cards[idx]);
+               if (snd_saa7134_cards[idx])
+                       snd_card_free(snd_saa7134_cards[idx]);
        }
 
        saa7134_dmasound_init = NULL;