V4L/DVB (12004): poll method lose race condition
[safe/jmp/linux-2.6] / drivers / media / video / cx88 / cx88-video.c
index d7d4d2a..0ccac70 100644 (file)
@@ -428,10 +428,8 @@ int cx88_video_mux(struct cx88_core *core, unsigned int input)
                   routes for different inputs. HVR-1300 surely does */
                if (core->board.audio_chip &&
                    core->board.audio_chip == V4L2_IDENT_WM8775) {
-                       struct v4l2_routing route;
-
-                       route.input = INPUT(input).audioroute;
-                       call_all(core, audio, s_routing, &route);
+                       call_all(core, audio, s_routing,
+                                       INPUT(input).audioroute, 0, 0);
                }
                /* cx2388's C-ADC is connected to the tuner only.
                   When used with S-Video, that ADC is busy dealing with
@@ -823,10 +821,8 @@ static int video_open(struct file *file)
                if (core->board.radio.audioroute) {
                        if(core->board.audio_chip &&
                                core->board.audio_chip == V4L2_IDENT_WM8775) {
-                               struct v4l2_routing route;
-
-                               route.input = core->board.radio.audioroute;
-                               call_all(core, audio, s_routing, &route);
+                               call_all(core, audio, s_routing,
+                                       core->board.radio.audioroute, 0, 0);
                        }
                        /* "I2S ADC mode" */
                        core->tvaudio = WW_I2SADC;
@@ -873,6 +869,7 @@ video_poll(struct file *file, struct poll_table_struct *wait)
 {
        struct cx8800_fh *fh = file->private_data;
        struct cx88_buffer *buf;
+       unsigned int rc = POLLERR;
 
        if (V4L2_BUF_TYPE_VBI_CAPTURE == fh->type) {
                if (!res_get(fh->dev,fh,RESOURCE_VBI))
@@ -880,22 +877,27 @@ video_poll(struct file *file, struct poll_table_struct *wait)
                return videobuf_poll_stream(file, &fh->vbiq, wait);
        }
 
+       mutex_lock(&fh->vidq.vb_lock);
        if (res_check(fh,RESOURCE_VIDEO)) {
                /* streaming capture */
                if (list_empty(&fh->vidq.stream))
-                       return POLLERR;
+                       goto done;
                buf = list_entry(fh->vidq.stream.next,struct cx88_buffer,vb.stream);
        } else {
                /* read() capture */
                buf = (struct cx88_buffer*)fh->vidq.read_buf;
                if (NULL == buf)
-                       return POLLERR;
+                       goto done;
        }
        poll_wait(file, &buf->vb.done, wait);
        if (buf->vb.state == VIDEOBUF_DONE ||
            buf->vb.state == VIDEOBUF_ERROR)
-               return POLLIN|POLLRDNORM;
-       return 0;
+               rc = POLLIN|POLLRDNORM;
+       else
+               rc = 0;
+done:
+       mutex_unlock(&fh->vidq.vb_lock);
+       return rc;
 }
 
 static int video_release(struct file *file)
@@ -930,8 +932,10 @@ static int video_release(struct file *file)
        file->private_data = NULL;
        kfree(fh);
 
+       mutex_lock(&dev->core->lock);
        if(atomic_dec_and_test(&dev->core->users))
                call_all(dev->core, tuner, s_standby);
+       mutex_unlock(&dev->core->lock);
 
        return 0;
 }
@@ -1836,7 +1840,7 @@ static int __devinit cx8800_initdev(struct pci_dev *pci_dev,
               dev->pci_lat,(unsigned long long)pci_resource_start(pci_dev,0));
 
        pci_set_master(pci_dev);
-       if (!pci_dma_supported(pci_dev,DMA_32BIT_MASK)) {
+       if (!pci_dma_supported(pci_dev,DMA_BIT_MASK(32))) {
                printk("%s/0: Oops: no 32bit PCI DMA ???\n",core->name);
                err = -EIO;
                goto fail_core;
@@ -1888,12 +1892,9 @@ static int __devinit cx8800_initdev(struct pci_dev *pci_dev,
        if (core->board.audio_chip == V4L2_IDENT_TVAUDIO) {
                /* This probes for a tda9874 as is used on some
                   Pixelview Ultra boards. */
-               static const unsigned short i2c_addr[] = {
-                       0xb0 >> 1, I2C_CLIENT_END
-               };
-
-               v4l2_i2c_new_probed_subdev(&core->v4l2_dev, &core->i2c_adap,
-                               "tvaudio", "tvaudio", i2c_addr);
+               v4l2_i2c_new_probed_subdev_addr(&core->v4l2_dev,
+                               &core->i2c_adap,
+                               "tvaudio", "tvaudio", 0xb0 >> 1);
        }
 
        switch (core->boardnr) {