Skip to contentSkip to conversation

saa7134-video.c: poll method lose race condition for capture video

PATCH New figo.zhang 1 participant 1 message May 19, 2009 Media (V4L/DVB)

lore
Share & tools
lore

figo.zhang

author
#0 lore raw

PATCH v2 1/1 saa7134-video.c: poll method lose race condition for capture video

saa7134-video.c: poll method lose race condition for capture video.

In v2, when buf == NULL, it will goto err, return "PULLERR" immediately.

---
drivers/media/video/saa7134/saa7134-video.c | 9 ++++++---

 1 files changed, 6 insertions(+), 3 deletions(-)
drivers/media/video/saa7134/saa7134-video.c +6 -3
index 493cad9..b1c2dbd 100644
@@ -1423,11 +1423,13 @@ video_poll(struct file *file, struct poll_table_struct *wait)
 {
 	struct saa7134_fh *fh = file->private_data;
 	struct videobuf_buffer *buf = NULL;
+	unsigned int rc = 0;
 
 	if (V4L2_BUF_TYPE_VBI_CAPTURE == fh->type)
 		return videobuf_poll_stream(file, &fh->vbi, wait);
 
 	if (res_check(fh,RESOURCE_VIDEO)) {
+		mutex_lock(&fh->cap.vb_lock);
 		if (!list_empty(&fh->cap.stream))
 			buf = list_entry(fh->cap.stream.next, struct videobuf_buffer, stream);
 	} else {
@@ -1446,13 +1448,14 @@ video_poll(struct file *file, struct poll_table_struct *wait)
 	}
 
 	if (!buf)
-		return POLLERR;
+		goto err;
 
 	poll_wait(file, &buf->done, wait);
 	if (buf->state == VIDEOBUF_DONE ||
 	    buf->state == VIDEOBUF_ERROR)
-		return POLLIN|POLLRDNORM;
-	return 0;
+		rc =  POLLIN|POLLRDNORM;
+	mutex_unlock(&fh->cap.vb_lock);
+	return rc;
 
 err:
 	mutex_unlock(&fh->cap.vb_lock);