Skip to contentSkip to conversation

saa7134-video.c: poll method lose race condition

PATCH Superseded figo.zhang 4 participants 9 messages May 18, 2009 Media (V4L/DVB)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

figo.zhang

author
#0 lore raw

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

saa7134-video.c: poll method lose race condition

---
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..95733df 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;
+		rc = POLLERR;
 
 	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);
#1 lore raw

Am Montag, den 18.05.2009, 10:13 +0800 schrieb figo.zhang:

Quoted 36 lines

saa7134-video.c: poll method lose race condition

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

 1 files changed, 6 insertions(+), 3 deletions(-)
drivers/media/video/saa7134/saa7134-video.c +3 -1
index 493cad9..95733df 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;
+		rc = POLLERR;
 
 	poll_wait(file, &buf->done, wait);

drivers/media/video/saa7134/saa7134-video.c video_poll(struct file *file, struct poll_table_struct *wait) · line 1461

Quoted 10 lines
drivers/media/video/saa7134/saa7134-video.c +3 -2
 	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);

Can you please give some description on what your patch might do something?

Or are you a robot?

Then, please give us your serial number, production year, and when we can expect you are out of duty and replaced ;)

Cheers,
Hermann

author
#2 lore raw
Quoted 51 lines · hermann pitton

Am Montag, den 18.05.2009, 10:13 +0800 schrieb figo.zhang:

Quoted 36 lines

saa7134-video.c: poll method lose race condition

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

 1 files changed, 6 insertions(+), 3 deletions(-)
drivers/media/video/saa7134/saa7134-video.c +3 -1
index 493cad9..95733df 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;
+		rc = POLLERR;
 
 	poll_wait(file, &buf->done, wait);

drivers/media/video/saa7134/saa7134-video.c video_poll(struct file *file, struct poll_table_struct *wait) · line 1461

Quoted 10 lines
drivers/media/video/saa7134/saa7134-video.c +3 -2
 	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);

Can you please give some description on what your patch might do something?

Quoted 10 lines

Or are you a robot?

Then, please give us your serial number, production year, and when we can expect you are out of duty and replaced ;)

Cheers,
Hermann

hi, I just using the saa7134 chip to do a video capture card. The saa7134 driver in linux kernel, i found that the poll method have lose race condition for "RESOURCE_VIDEO". It have better to add a mutex lock.

#3 lore raw

Am Montag, den 18.05.2009, 11:53 +0800 schrieb figo.zhang:

Quoted 63 lines · hermann pitton
Quoted 51 lines

Am Montag, den 18.05.2009, 10:13 +0800 schrieb figo.zhang:

Quoted 36 lines

saa7134-video.c: poll method lose race condition

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

 1 files changed, 6 insertions(+), 3 deletions(-)
drivers/media/video/saa7134/saa7134-video.c +3 -1
index 493cad9..95733df 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;
+		rc = POLLERR;
 
 	poll_wait(file, &buf->done, wait);

drivers/media/video/saa7134/saa7134-video.c video_poll(struct file *file, struct poll_table_struct *wait) · line 1461

Quoted 10 lines
drivers/media/video/saa7134/saa7134-video.c +3 -2
 	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);

Can you please give some description on what your patch might do something?

Quoted 10 lines

Or are you a robot?

Then, please give us your serial number, production year, and when we can expect you are out of duty and replaced ;)

Cheers,
Hermann

Quoted 4 lines

hi, I just using the saa7134 chip to do a video capture card. The saa7134 driver in linux kernel, i found that the poll method have lose race condition for "RESOURCE_VIDEO". It have better to add a mutex lock.

OK then, but better stay away from the core files.

On what kernel this is?

Give us some copy/paste "dmesg" output for your card with "i2c_scan=1". Don't lose tuner stuff on this.

Thanks,
Hermann

author
#4 lore raw
Quoted 71 lines · hermann pitton

Am Montag, den 18.05.2009, 11:53 +0800 schrieb figo.zhang:

Quoted 63 lines · hermann pitton
Quoted 51 lines

Am Montag, den 18.05.2009, 10:13 +0800 schrieb figo.zhang:

Quoted 36 lines

saa7134-video.c: poll method lose race condition

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

 1 files changed, 6 insertions(+), 3 deletions(-)
drivers/media/video/saa7134/saa7134-video.c +3 -1
index 493cad9..95733df 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;
+		rc = POLLERR;
 
 	poll_wait(file, &buf->done, wait);

drivers/media/video/saa7134/saa7134-video.c video_poll(struct file *file, struct poll_table_struct *wait) · line 1461

Quoted 10 lines
drivers/media/video/saa7134/saa7134-video.c +3 -2
 	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);

Can you please give some description on what your patch might do something?

Quoted 10 lines

Or are you a robot?

Then, please give us your serial number, production year, and when we can expect you are out of duty and replaced ;)

Cheers,
Hermann

Quoted 4 lines

hi, I just using the saa7134 chip to do a video capture card. The saa7134 driver in linux kernel, i found that the poll method have lose race condition for "RESOURCE_VIDEO". It have better to add a mutex lock.

OK then, but better stay away from the core files.

Quoted 10 lines

On what kernel this is?

Give us some copy/paste "dmesg" output for your card with "i2c_scan=1". Don't lose tuner stuff on this.

Thanks,
Hermann

hi, hermann pitton ,i am using the git-kernel, the card have some hardware problems now.

#5 lore raw

[big snip]

Quoted 5 lines
Quoted 3 lines

hi, hermann pitton ,i am using the git-kernel, the card have some hardware problems now.

If it is a new card, 2.6.27 is for sure the last stable.

We might get it all down, but 2.6.30 looked promising again.

Seems there is some hungry black hole in between ;)

Cheers,
Hermann

author
#7 lore raw
Quoted 1 line · Guennadi Liakhovetski

Guennadi

hi,Guennadi,

I am sorry that it is my mistake.

Figo.zhang

#8 lore raw
In reply to figo.zhang

Hi Figo Zhang,

Quoted 27 lines · figo.zhang

saa7134-video.c: poll method lose race condition

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

 1 files changed, 6 insertions(+), 3 deletions(-)
(quoted diff) +0 -0

b/drivers/media/video/saa7134/saa7134-video.c index 493cad9..95733df 100644

drivers/media/video/saa7134/saa7134-video.c +2 -0
@@ -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 {

drivers/media/video/saa7134/saa7134-video.c video_poll(struct file *file, struct · line 1451

Quoted 5 lines
drivers/media/video/saa7134/saa7134-video.c +1 -1
@@ -1446,13 +1448,14 @@ video_poll(struct file *file, struct
 poll_table_struct *wait) }
 
 	if (!buf)
-		return POLLERR;
+		rc = POLLERR;

Just one note (I don't know the future and meaning of this patch). The line above will change the meaning of the buf==NULL check. It will not return immediately, but call poll_wait with buf->done instead - NULL pointer access.

Cheers,
Oldrich.

Quoted 18 lines
drivers/media/video/saa7134/saa7134-video.c +3 -3
 	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);
 
 
--

To unsubscribe from this list: send the line "unsubscribe linux-media" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html