All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] cx23885/vb2 regression: please test this patch
@ 2015-01-13 14:01 Hans Verkuil
  2015-01-13 16:59 ` Jurgen Kramer
  2015-01-13 17:55 ` Raimonds Cicans
  0 siblings, 2 replies; 19+ messages in thread
From: Hans Verkuil @ 2015-01-13 14:01 UTC (permalink / raw)
  To: linux-media, gtmkramer, ray

Hi Raimonds, Jurgen,

Can you both test this patch? It should (I hope) solve the problems you
both had with the cx23885 driver.

This patch fixes a race condition in the vb2_thread that occurs when
the thread is stopped. The crucial fix is calling kthread_stop much
earlier in vb2_thread_stop(). But I also made the vb2_thread more
robust.

Regards,

	Hans

Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>

diff --git a/drivers/media/v4l2-core/videobuf2-core.c b/drivers/media/v4l2-core/videobuf2-core.c
index d09a891..bc08a82 100644
--- a/drivers/media/v4l2-core/videobuf2-core.c
+++ b/drivers/media/v4l2-core/videobuf2-core.c
@@ -3146,27 +3146,26 @@ static int vb2_thread(void *data)
 			prequeue--;
 		} else {
 			call_void_qop(q, wait_finish, q);
-			ret = vb2_internal_dqbuf(q, &fileio->b, 0);
+			if (!threadio->stop)
+				ret = vb2_internal_dqbuf(q, &fileio->b, 0);
 			call_void_qop(q, wait_prepare, q);
 			dprintk(5, "file io: vb2_dqbuf result: %d\n", ret);
 		}
-		if (threadio->stop)
-			break;
-		if (ret)
+		if (ret || threadio->stop)
 			break;
 		try_to_freeze();
 
 		vb = q->bufs[fileio->b.index];
 		if (!(fileio->b.flags & V4L2_BUF_FLAG_ERROR))
-			ret = threadio->fnc(vb, threadio->priv);
-		if (ret)
-			break;
+			if (threadio->fnc(vb, threadio->priv))
+				break;
 		call_void_qop(q, wait_finish, q);
 		if (set_timestamp)
 			v4l2_get_timestamp(&fileio->b.timestamp);
-		ret = vb2_internal_qbuf(q, &fileio->b);
+		if (!threadio->stop)
+			ret = vb2_internal_qbuf(q, &fileio->b);
 		call_void_qop(q, wait_prepare, q);
-		if (ret)
+		if (ret || threadio->stop)
 			break;
 	}
 
@@ -3235,11 +3234,11 @@ int vb2_thread_stop(struct vb2_queue *q)
 	threadio->stop = true;
 	vb2_internal_streamoff(q, q->type);
 	call_void_qop(q, wait_prepare, q);
+	err = kthread_stop(threadio->thread);
 	q->fileio = NULL;
 	fileio->req.count = 0;
 	vb2_reqbufs(q, &fileio->req);
 	kfree(fileio);
-	err = kthread_stop(threadio->thread);
 	threadio->thread = NULL;
 	kfree(threadio);
 	q->fileio = NULL;

^ permalink raw reply related	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2015-01-18 12:35 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-01-13 14:01 [PATCH] cx23885/vb2 regression: please test this patch Hans Verkuil
2015-01-13 16:59 ` Jurgen Kramer
2015-01-15 16:32   ` Jurgen Kramer
2015-01-16 14:58     ` Hans Verkuil
2015-01-16 16:48       ` Jurgen Kramer
2015-01-18  8:54       ` Jurgen Kramer
2015-01-18 10:40         ` Hans Verkuil
2015-01-18 12:35           ` Jurgen Kramer
2015-01-13 17:55 ` Raimonds Cicans
2015-01-14  6:16   ` Raimonds Cicans
2015-01-16 14:54   ` Hans Verkuil
2015-01-16 16:20     ` Raimonds Cicans
2015-01-16 16:48       ` Luis Alves
2015-01-16 17:38         ` Hans Verkuil
2015-01-16 17:40       ` Hans Verkuil
2015-01-16 19:05     ` Raimonds Cicans
2015-01-17 11:09       ` Hans Verkuil
2015-01-17 12:02         ` Raimonds Cicans
2015-01-17 12:30         ` Tycho Lürsen

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.