linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 1/4] vb2: Merge vb2_internal_dqbuf and vb2_dqbuf
@ 2016-06-20 12:30 Ricardo Ribalda Delgado
  2016-06-20 12:30 ` [PATCH v2 2/4] vb2: Merge vb2_internal_qbuf and vb2_qbuf Ricardo Ribalda Delgado
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Ricardo Ribalda Delgado @ 2016-06-20 12:30 UTC (permalink / raw)
  To: Pawel Osciak, Marek Szyprowski, Kyungmin Park,
	Mauro Carvalho Chehab, linux-media, linux-kernel, hans.verkuil,
	hverkuil
  Cc: Ricardo Ribalda Delgado

After all the code refactoring, vb2_internal_dqbuf is only called by
vb2_dqbuf.

Since the function it is very simple, there is no need to have two
functions.

Signed-off-by: Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com>
---
 drivers/media/v4l2-core/videobuf2-v4l2.c | 27 +++++++++++----------------
 1 file changed, 11 insertions(+), 16 deletions(-)

diff --git a/drivers/media/v4l2-core/videobuf2-v4l2.c b/drivers/media/v4l2-core/videobuf2-v4l2.c
index 7f366f1b0377..07d8b409ce05 100644
--- a/drivers/media/v4l2-core/videobuf2-v4l2.c
+++ b/drivers/media/v4l2-core/videobuf2-v4l2.c
@@ -621,21 +621,6 @@ int vb2_qbuf(struct vb2_queue *q, struct v4l2_buffer *b)
 }
 EXPORT_SYMBOL_GPL(vb2_qbuf);
 
-static int vb2_internal_dqbuf(struct vb2_queue *q, struct v4l2_buffer *b,
-		bool nonblocking)
-{
-	int ret;
-
-	if (b->type != q->type) {
-		dprintk(1, "invalid buffer type\n");
-		return -EINVAL;
-	}
-
-	ret = vb2_core_dqbuf(q, NULL, b, nonblocking);
-
-	return ret;
-}
-
 /**
  * vb2_dqbuf() - Dequeue a buffer to the userspace
  * @q:		videobuf2 queue
@@ -659,11 +644,21 @@ static int vb2_internal_dqbuf(struct vb2_queue *q, struct v4l2_buffer *b,
  */
 int vb2_dqbuf(struct vb2_queue *q, struct v4l2_buffer *b, bool nonblocking)
 {
+	int ret;
+
 	if (vb2_fileio_is_active(q)) {
 		dprintk(1, "file io in progress\n");
 		return -EBUSY;
 	}
-	return vb2_internal_dqbuf(q, b, nonblocking);
+
+	if (b->type != q->type) {
+		dprintk(1, "invalid buffer type\n");
+		return -EINVAL;
+	}
+
+	ret = vb2_core_dqbuf(q, NULL, b, nonblocking);
+
+	return ret;
 }
 EXPORT_SYMBOL_GPL(vb2_dqbuf);
 
-- 
2.8.1

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

* [PATCH v2 2/4] vb2: Merge vb2_internal_qbuf and vb2_qbuf
  2016-06-20 12:30 [PATCH v2 1/4] vb2: Merge vb2_internal_dqbuf and vb2_dqbuf Ricardo Ribalda Delgado
@ 2016-06-20 12:30 ` Ricardo Ribalda Delgado
  2016-06-20 12:30 ` [PATCH v2 3/4] vb2: Fix comment Ricardo Ribalda Delgado
  2016-06-20 12:30 ` [PATCH v2 4/4] vb2: V4L2_BUF_FLAG_DONE is set after DQBUF Ricardo Ribalda Delgado
  2 siblings, 0 replies; 5+ messages in thread
From: Ricardo Ribalda Delgado @ 2016-06-20 12:30 UTC (permalink / raw)
  To: Pawel Osciak, Marek Szyprowski, Kyungmin Park,
	Mauro Carvalho Chehab, linux-media, linux-kernel, hans.verkuil,
	hverkuil
  Cc: Ricardo Ribalda Delgado

After all the code refactoring, vb2_internal_dqbuf is only called by
vb2_dqbuf.

Since the function it is very simple, there is no need to have
two functions.

Signed-off-by: Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com>
---
 drivers/media/v4l2-core/videobuf2-v4l2.c | 14 +++++---------
 1 file changed, 5 insertions(+), 9 deletions(-)

diff --git a/drivers/media/v4l2-core/videobuf2-v4l2.c b/drivers/media/v4l2-core/videobuf2-v4l2.c
index 07d8b409ce05..ba3467468e55 100644
--- a/drivers/media/v4l2-core/videobuf2-v4l2.c
+++ b/drivers/media/v4l2-core/videobuf2-v4l2.c
@@ -427,7 +427,7 @@ static int __fill_vb2_buffer(struct vb2_buffer *vb,
 	if (V4L2_TYPE_IS_OUTPUT(b->type)) {
 		/*
 		 * For output buffers mask out the timecode flag:
-		 * this will be handled later in vb2_internal_qbuf().
+		 * this will be handled later in vb2_qbuf().
 		 * The 'field' is valid metadata for this output buffer
 		 * and so that needs to be copied here.
 		 */
@@ -586,13 +586,6 @@ int vb2_create_bufs(struct vb2_queue *q, struct v4l2_create_buffers *create)
 }
 EXPORT_SYMBOL_GPL(vb2_create_bufs);
 
-static int vb2_internal_qbuf(struct vb2_queue *q, struct v4l2_buffer *b)
-{
-	int ret = vb2_queue_or_prepare_buf(q, b, "qbuf");
-
-	return ret ? ret : vb2_core_qbuf(q, b->index, b);
-}
-
 /**
  * vb2_qbuf() - Queue a buffer from userspace
  * @q:		videobuf2 queue
@@ -612,12 +605,15 @@ static int vb2_internal_qbuf(struct vb2_queue *q, struct v4l2_buffer *b)
  */
 int vb2_qbuf(struct vb2_queue *q, struct v4l2_buffer *b)
 {
+	int ret;
+
 	if (vb2_fileio_is_active(q)) {
 		dprintk(1, "file io in progress\n");
 		return -EBUSY;
 	}
 
-	return vb2_internal_qbuf(q, b);
+	ret = vb2_queue_or_prepare_buf(q, b, "qbuf");
+	return ret ? ret : vb2_core_qbuf(q, b->index, b);
 }
 EXPORT_SYMBOL_GPL(vb2_qbuf);
 
-- 
2.8.1

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

* [PATCH v2 3/4] vb2: Fix comment
  2016-06-20 12:30 [PATCH v2 1/4] vb2: Merge vb2_internal_dqbuf and vb2_dqbuf Ricardo Ribalda Delgado
  2016-06-20 12:30 ` [PATCH v2 2/4] vb2: Merge vb2_internal_qbuf and vb2_qbuf Ricardo Ribalda Delgado
@ 2016-06-20 12:30 ` Ricardo Ribalda Delgado
  2016-06-20 12:30 ` [PATCH v2 4/4] vb2: V4L2_BUF_FLAG_DONE is set after DQBUF Ricardo Ribalda Delgado
  2 siblings, 0 replies; 5+ messages in thread
From: Ricardo Ribalda Delgado @ 2016-06-20 12:30 UTC (permalink / raw)
  To: Pawel Osciak, Marek Szyprowski, Kyungmin Park,
	Mauro Carvalho Chehab, linux-media, linux-kernel, hans.verkuil,
	hverkuil
  Cc: Ricardo Ribalda Delgado

The comment was referencing the wrong function.

Signed-off-by: Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com>
---
 drivers/media/v4l2-core/videobuf2-core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/v4l2-core/videobuf2-core.c b/drivers/media/v4l2-core/videobuf2-core.c
index 633fc1ab1d7a..ba6ab8b7311f 100644
--- a/drivers/media/v4l2-core/videobuf2-core.c
+++ b/drivers/media/v4l2-core/videobuf2-core.c
@@ -1845,7 +1845,7 @@ static void __vb2_queue_cancel(struct vb2_queue *q)
 	 * Make sure to call buf_finish for any queued buffers. Normally
 	 * that's done in dqbuf, but that's not going to happen when we
 	 * cancel the whole queue. Note: this code belongs here, not in
-	 * __vb2_dqbuf() since in vb2_internal_dqbuf() there is a critical
+	 * __vb2_dqbuf() since in vb2_core_dqbuf() there is a critical
 	 * call to __fill_user_buffer() after buf_finish(). That order can't
 	 * be changed, so we can't move the buf_finish() to __vb2_dqbuf().
 	 */
-- 
2.8.1

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

* [PATCH v2 4/4] vb2: V4L2_BUF_FLAG_DONE is set after DQBUF
  2016-06-20 12:30 [PATCH v2 1/4] vb2: Merge vb2_internal_dqbuf and vb2_dqbuf Ricardo Ribalda Delgado
  2016-06-20 12:30 ` [PATCH v2 2/4] vb2: Merge vb2_internal_qbuf and vb2_qbuf Ricardo Ribalda Delgado
  2016-06-20 12:30 ` [PATCH v2 3/4] vb2: Fix comment Ricardo Ribalda Delgado
@ 2016-06-20 12:30 ` Ricardo Ribalda Delgado
  2016-06-20 12:38   ` Hans Verkuil
  2 siblings, 1 reply; 5+ messages in thread
From: Ricardo Ribalda Delgado @ 2016-06-20 12:30 UTC (permalink / raw)
  To: Pawel Osciak, Marek Szyprowski, Kyungmin Park,
	Mauro Carvalho Chehab, linux-media, linux-kernel, hans.verkuil,
	hverkuil
  Cc: Ricardo Ribalda Delgado

According to the doc, V4L2_BUF_FLAG_DONE is cleared after DQBUF:

V4L2_BUF_FLAG_DONE 0x00000004  ... After calling the VIDIOC_QBUF or
VIDIOC_DQBUF it is always cleared ...

Unfortunately, it seems that videobuf2 keeps it set after DQBUF. This
can be tested with vivid and dev_debug:

[257604.338082] video1: VIDIOC_DQBUF: 71:33:25.00260479 index=3,
type=vid-cap, flags=0x00002004, field=none, sequence=163,
memory=userptr, bytesused=460800, offset/userptr=0x344b000,
length=460800

This patch forces FLAG_DONE to 0 after calling DQBUF.

Reported-by: Dimitrios Katsaros <patcherwork@gmail.com>
Signed-off-by: Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com>
---
 drivers/media/v4l2-core/videobuf2-v4l2.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/media/v4l2-core/videobuf2-v4l2.c b/drivers/media/v4l2-core/videobuf2-v4l2.c
index ba3467468e55..9cfbb6e4bc28 100644
--- a/drivers/media/v4l2-core/videobuf2-v4l2.c
+++ b/drivers/media/v4l2-core/videobuf2-v4l2.c
@@ -654,6 +654,12 @@ int vb2_dqbuf(struct vb2_queue *q, struct v4l2_buffer *b, bool nonblocking)
 
 	ret = vb2_core_dqbuf(q, NULL, b, nonblocking);
 
+	/*
+	 *  After calling the VIDIOC_DQBUF V4L2_BUF_FLAG_DONE must be
+	 *  cleared.
+	 */
+	b->flags &= ~V4L2_BUF_FLAG_DONE;
+
 	return ret;
 }
 EXPORT_SYMBOL_GPL(vb2_dqbuf);
-- 
2.8.1

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

* Re: [PATCH v2 4/4] vb2: V4L2_BUF_FLAG_DONE is set after DQBUF
  2016-06-20 12:30 ` [PATCH v2 4/4] vb2: V4L2_BUF_FLAG_DONE is set after DQBUF Ricardo Ribalda Delgado
@ 2016-06-20 12:38   ` Hans Verkuil
  0 siblings, 0 replies; 5+ messages in thread
From: Hans Verkuil @ 2016-06-20 12:38 UTC (permalink / raw)
  To: Ricardo Ribalda Delgado, Pawel Osciak, Marek Szyprowski,
	Kyungmin Park, Mauro Carvalho Chehab, linux-media, linux-kernel,
	hans.verkuil, hverkuil

On 06/20/2016 02:30 PM, Ricardo Ribalda Delgado wrote:
> According to the doc, V4L2_BUF_FLAG_DONE is cleared after DQBUF:
>
> V4L2_BUF_FLAG_DONE 0x00000004  ... After calling the VIDIOC_QBUF or
> VIDIOC_DQBUF it is always cleared ...
>
> Unfortunately, it seems that videobuf2 keeps it set after DQBUF. This
> can be tested with vivid and dev_debug:
>
> [257604.338082] video1: VIDIOC_DQBUF: 71:33:25.00260479 index=3,
> type=vid-cap, flags=0x00002004, field=none, sequence=163,
> memory=userptr, bytesused=460800, offset/userptr=0x344b000,
> length=460800
>
> This patch forces FLAG_DONE to 0 after calling DQBUF.

Can you change this to be patch 1/4? That makes it much easier to backport to
older kernels. I'm not sure if I'll actually do that, but putting this patch
at the end makes it harder than it needs to be.

Regards,

	Hans

>
> Reported-by: Dimitrios Katsaros <patcherwork@gmail.com>
> Signed-off-by: Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com>
> ---
>   drivers/media/v4l2-core/videobuf2-v4l2.c | 6 ++++++
>   1 file changed, 6 insertions(+)
>
> diff --git a/drivers/media/v4l2-core/videobuf2-v4l2.c b/drivers/media/v4l2-core/videobuf2-v4l2.c
> index ba3467468e55..9cfbb6e4bc28 100644
> --- a/drivers/media/v4l2-core/videobuf2-v4l2.c
> +++ b/drivers/media/v4l2-core/videobuf2-v4l2.c
> @@ -654,6 +654,12 @@ int vb2_dqbuf(struct vb2_queue *q, struct v4l2_buffer *b, bool nonblocking)
>
>   	ret = vb2_core_dqbuf(q, NULL, b, nonblocking);
>
> +	/*
> +	 *  After calling the VIDIOC_DQBUF V4L2_BUF_FLAG_DONE must be
> +	 *  cleared.
> +	 */
> +	b->flags &= ~V4L2_BUF_FLAG_DONE;
> +
>   	return ret;
>   }
>   EXPORT_SYMBOL_GPL(vb2_dqbuf);
>

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

end of thread, other threads:[~2016-06-20 12:49 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-06-20 12:30 [PATCH v2 1/4] vb2: Merge vb2_internal_dqbuf and vb2_dqbuf Ricardo Ribalda Delgado
2016-06-20 12:30 ` [PATCH v2 2/4] vb2: Merge vb2_internal_qbuf and vb2_qbuf Ricardo Ribalda Delgado
2016-06-20 12:30 ` [PATCH v2 3/4] vb2: Fix comment Ricardo Ribalda Delgado
2016-06-20 12:30 ` [PATCH v2 4/4] vb2: V4L2_BUF_FLAG_DONE is set after DQBUF Ricardo Ribalda Delgado
2016-06-20 12:38   ` Hans Verkuil

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).