All of lore.kernel.org
 help / color / mirror / Atom feed
From: Hans Verkuil <hverkuil@xs4all.nl>
To: linux-media <linux-media@vger.kernel.org>,
	gtmkramer@xs4all.nl, ray@apollo.lv
Subject: [PATCH] cx23885/vb2 regression: please test this patch
Date: Tue, 13 Jan 2015 15:01:44 +0100	[thread overview]
Message-ID: <54B52548.7010109@xs4all.nl> (raw)

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;

             reply	other threads:[~2015-01-13 14:02 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-13 14:01 Hans Verkuil [this message]
2015-01-13 16:59 ` [PATCH] cx23885/vb2 regression: please test this patch 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=54B52548.7010109@xs4all.nl \
    --to=hverkuil@xs4all.nl \
    --cc=gtmkramer@xs4all.nl \
    --cc=linux-media@vger.kernel.org \
    --cc=ray@apollo.lv \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.