aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFigo.zhang <figo1802@gmail.com>2009-06-16 12:31:29 -0400
committerMauro Carvalho Chehab <mchehab@redhat.com>2009-06-16 18:14:44 -0400
commit9fd6418a6a7655b69cfa0ae27a3639a6d0b2924f (patch)
tree3b3754a6518f7cefb130b314199733daaf831d2b
parent1c905a4522a3913cf321365c5bb62eb2f70d55d9 (diff)
V4L/DVB (12004): poll method lose race condition
bttv-driver.c,cx23885-video.c,cx88-video.c: poll method lose race condition for capture video. Signed-off-by: Figo.zhang <figo1802@gmail.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
-rw-r--r--drivers/media/video/bt8xx/bttv-driver.c11
-rw-r--r--drivers/media/video/cx23885/cx23885-video.c14
-rw-r--r--drivers/media/video/cx88/cx88-video.c14
3 files changed, 27 insertions, 12 deletions
diff --git a/drivers/media/video/bt8xx/bttv-driver.c b/drivers/media/video/bt8xx/bttv-driver.c
index 7c1f82661ee8..5eb1464af670 100644
--- a/drivers/media/video/bt8xx/bttv-driver.c
+++ b/drivers/media/video/bt8xx/bttv-driver.c
@@ -3152,6 +3152,7 @@ static unsigned int bttv_poll(struct file *file, poll_table *wait)
3152 struct bttv_fh *fh = file->private_data; 3152 struct bttv_fh *fh = file->private_data;
3153 struct bttv_buffer *buf; 3153 struct bttv_buffer *buf;
3154 enum v4l2_field field; 3154 enum v4l2_field field;
3155 unsigned int rc = POLLERR;
3155 3156
3156 if (V4L2_BUF_TYPE_VBI_CAPTURE == fh->type) { 3157 if (V4L2_BUF_TYPE_VBI_CAPTURE == fh->type) {
3157 if (!check_alloc_btres(fh->btv,fh,RESOURCE_VBI)) 3158 if (!check_alloc_btres(fh->btv,fh,RESOURCE_VBI))
@@ -3160,9 +3161,10 @@ static unsigned int bttv_poll(struct file *file, poll_table *wait)
3160 } 3161 }
3161 3162
3162 if (check_btres(fh,RESOURCE_VIDEO_STREAM)) { 3163 if (check_btres(fh,RESOURCE_VIDEO_STREAM)) {
3164 mutex_lock(&fh->cap.vb_lock);
3163 /* streaming capture */ 3165 /* streaming capture */
3164 if (list_empty(&fh->cap.stream)) 3166 if (list_empty(&fh->cap.stream))
3165 return POLLERR; 3167 goto err;
3166 buf = list_entry(fh->cap.stream.next,struct bttv_buffer,vb.stream); 3168 buf = list_entry(fh->cap.stream.next,struct bttv_buffer,vb.stream);
3167 } else { 3169 } else {
3168 /* read() capture */ 3170 /* read() capture */
@@ -3191,11 +3193,12 @@ static unsigned int bttv_poll(struct file *file, poll_table *wait)
3191 poll_wait(file, &buf->vb.done, wait); 3193 poll_wait(file, &buf->vb.done, wait);
3192 if (buf->vb.state == VIDEOBUF_DONE || 3194 if (buf->vb.state == VIDEOBUF_DONE ||
3193 buf->vb.state == VIDEOBUF_ERROR) 3195 buf->vb.state == VIDEOBUF_ERROR)
3194 return POLLIN|POLLRDNORM; 3196 rc = POLLIN|POLLRDNORM;
3195 return 0; 3197 else
3198 rc = 0;
3196err: 3199err:
3197 mutex_unlock(&fh->cap.vb_lock); 3200 mutex_unlock(&fh->cap.vb_lock);
3198 return POLLERR; 3201 return rc;
3199} 3202}
3200 3203
3201static int bttv_open(struct file *file) 3204static int bttv_open(struct file *file)
diff --git a/drivers/media/video/cx23885/cx23885-video.c b/drivers/media/video/cx23885/cx23885-video.c
index 68068c6d0987..66bbd2e71105 100644
--- a/drivers/media/video/cx23885/cx23885-video.c
+++ b/drivers/media/video/cx23885/cx23885-video.c
@@ -796,6 +796,7 @@ static unsigned int video_poll(struct file *file,
796{ 796{
797 struct cx23885_fh *fh = file->private_data; 797 struct cx23885_fh *fh = file->private_data;
798 struct cx23885_buffer *buf; 798 struct cx23885_buffer *buf;
799 unsigned int rc = POLLERR;
799 800
800 if (V4L2_BUF_TYPE_VBI_CAPTURE == fh->type) { 801 if (V4L2_BUF_TYPE_VBI_CAPTURE == fh->type) {
801 if (!res_get(fh->dev, fh, RESOURCE_VBI)) 802 if (!res_get(fh->dev, fh, RESOURCE_VBI))
@@ -803,23 +804,28 @@ static unsigned int video_poll(struct file *file,
803 return videobuf_poll_stream(file, &fh->vbiq, wait); 804 return videobuf_poll_stream(file, &fh->vbiq, wait);
804 } 805 }
805 806
807 mutex_lock(&fh->vidq.vb_lock);
806 if (res_check(fh, RESOURCE_VIDEO)) { 808 if (res_check(fh, RESOURCE_VIDEO)) {
807 /* streaming capture */ 809 /* streaming capture */
808 if (list_empty(&fh->vidq.stream)) 810 if (list_empty(&fh->vidq.stream))
809 return POLLERR; 811 goto done;
810 buf = list_entry(fh->vidq.stream.next, 812 buf = list_entry(fh->vidq.stream.next,
811 struct cx23885_buffer, vb.stream); 813 struct cx23885_buffer, vb.stream);
812 } else { 814 } else {
813 /* read() capture */ 815 /* read() capture */
814 buf = (struct cx23885_buffer *)fh->vidq.read_buf; 816 buf = (struct cx23885_buffer *)fh->vidq.read_buf;
815 if (NULL == buf) 817 if (NULL == buf)
816 return POLLERR; 818 goto done;
817 } 819 }
818 poll_wait(file, &buf->vb.done, wait); 820 poll_wait(file, &buf->vb.done, wait);
819 if (buf->vb.state == VIDEOBUF_DONE || 821 if (buf->vb.state == VIDEOBUF_DONE ||
820 buf->vb.state == VIDEOBUF_ERROR) 822 buf->vb.state == VIDEOBUF_ERROR)
821 return POLLIN|POLLRDNORM; 823 rc = POLLIN|POLLRDNORM;
822 return 0; 824 else
825 rc = 0;
826done:
827 mutex_unlock(&fh->vidq.vb_lock);
828 return rc;
823} 829}
824 830
825static int video_release(struct file *file) 831static int video_release(struct file *file)
diff --git a/drivers/media/video/cx88/cx88-video.c b/drivers/media/video/cx88/cx88-video.c
index d6d6d13a6a6b..0ccac702bea4 100644
--- a/drivers/media/video/cx88/cx88-video.c
+++ b/drivers/media/video/cx88/cx88-video.c
@@ -869,6 +869,7 @@ video_poll(struct file *file, struct poll_table_struct *wait)
869{ 869{
870 struct cx8800_fh *fh = file->private_data; 870 struct cx8800_fh *fh = file->private_data;
871 struct cx88_buffer *buf; 871 struct cx88_buffer *buf;
872 unsigned int rc = POLLERR;
872 873
873 if (V4L2_BUF_TYPE_VBI_CAPTURE == fh->type) { 874 if (V4L2_BUF_TYPE_VBI_CAPTURE == fh->type) {
874 if (!res_get(fh->dev,fh,RESOURCE_VBI)) 875 if (!res_get(fh->dev,fh,RESOURCE_VBI))
@@ -876,22 +877,27 @@ video_poll(struct file *file, struct poll_table_struct *wait)
876 return videobuf_poll_stream(file, &fh->vbiq, wait); 877 return videobuf_poll_stream(file, &fh->vbiq, wait);
877 } 878 }
878 879
880 mutex_lock(&fh->vidq.vb_lock);
879 if (res_check(fh,RESOURCE_VIDEO)) { 881 if (res_check(fh,RESOURCE_VIDEO)) {
880 /* streaming capture */ 882 /* streaming capture */
881 if (list_empty(&fh->vidq.stream)) 883 if (list_empty(&fh->vidq.stream))
882 return POLLERR; 884 goto done;
883 buf = list_entry(fh->vidq.stream.next,struct cx88_buffer,vb.stream); 885 buf = list_entry(fh->vidq.stream.next,struct cx88_buffer,vb.stream);
884 } else { 886 } else {
885 /* read() capture */ 887 /* read() capture */
886 buf = (struct cx88_buffer*)fh->vidq.read_buf; 888 buf = (struct cx88_buffer*)fh->vidq.read_buf;
887 if (NULL == buf) 889 if (NULL == buf)
888 return POLLERR; 890 goto done;
889 } 891 }
890 poll_wait(file, &buf->vb.done, wait); 892 poll_wait(file, &buf->vb.done, wait);
891 if (buf->vb.state == VIDEOBUF_DONE || 893 if (buf->vb.state == VIDEOBUF_DONE ||
892 buf->vb.state == VIDEOBUF_ERROR) 894 buf->vb.state == VIDEOBUF_ERROR)
893 return POLLIN|POLLRDNORM; 895 rc = POLLIN|POLLRDNORM;
894 return 0; 896 else
897 rc = 0;
898done:
899 mutex_unlock(&fh->vidq.vb_lock);
900 return rc;
895} 901}
896 902
897static int video_release(struct file *file) 903static int video_release(struct file *file)