Re: [PATCHv18 17/35] videobuf2-v4l2: move __fill_v4l2_buffer() function

2018-08-14 Thread Mauro Carvalho Chehab
Em Tue, 14 Aug 2018 16:20:29 +0200
Hans Verkuil  escreveu:

> From: Hans Verkuil 
> 
> Move the __fill_v4l2_buffer() to before the vb2_queue_or_prepare_buf()
> function to prepare for the next two patches.
> 
> No other changes.
> 
> Signed-off-by: Hans Verkuil 
Reviewed-by: Mauro Carvalho Chehab 

> ---
>  .../media/common/videobuf2/videobuf2-v4l2.c   | 264 +-
>  1 file changed, 132 insertions(+), 132 deletions(-)
> 
> diff --git a/drivers/media/common/videobuf2/videobuf2-v4l2.c 
> b/drivers/media/common/videobuf2/videobuf2-v4l2.c
> index 886a2d8d5c6c..408fd7ce9c09 100644
> --- a/drivers/media/common/videobuf2/videobuf2-v4l2.c
> +++ b/drivers/media/common/videobuf2/videobuf2-v4l2.c
> @@ -154,138 +154,6 @@ static void vb2_warn_zero_bytesused(struct vb2_buffer 
> *vb)
>   pr_warn("use the actual size instead.\n");
>  }
>  
> -static int vb2_queue_or_prepare_buf(struct vb2_queue *q, struct v4l2_buffer 
> *b,
> - const char *opname)
> -{
> - if (b->type != q->type) {
> - dprintk(1, "%s: invalid buffer type\n", opname);
> - return -EINVAL;
> - }
> -
> - if (b->index >= q->num_buffers) {
> - dprintk(1, "%s: buffer index out of range\n", opname);
> - return -EINVAL;
> - }
> -
> - if (q->bufs[b->index] == NULL) {
> - /* Should never happen */
> - dprintk(1, "%s: buffer is NULL\n", opname);
> - return -EINVAL;
> - }
> -
> - if (b->memory != q->memory) {
> - dprintk(1, "%s: invalid memory type\n", opname);
> - return -EINVAL;
> - }
> -
> - return __verify_planes_array(q->bufs[b->index], b);
> -}
> -
> -/*
> - * __fill_v4l2_buffer() - fill in a struct v4l2_buffer with information to be
> - * returned to userspace
> - */
> -static void __fill_v4l2_buffer(struct vb2_buffer *vb, void *pb)
> -{
> - struct v4l2_buffer *b = pb;
> - struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
> - struct vb2_queue *q = vb->vb2_queue;
> - unsigned int plane;
> -
> - /* Copy back data such as timestamp, flags, etc. */
> - b->index = vb->index;
> - b->type = vb->type;
> - b->memory = vb->memory;
> - b->bytesused = 0;
> -
> - b->flags = vbuf->flags;
> - b->field = vbuf->field;
> - b->timestamp = ns_to_timeval(vb->timestamp);
> - b->timecode = vbuf->timecode;
> - b->sequence = vbuf->sequence;
> - b->reserved2 = 0;
> - b->reserved = 0;
> -
> - if (q->is_multiplanar) {
> - /*
> -  * Fill in plane-related data if userspace provided an array
> -  * for it. The caller has already verified memory and size.
> -  */
> - b->length = vb->num_planes;
> - for (plane = 0; plane < vb->num_planes; ++plane) {
> - struct v4l2_plane *pdst = >m.planes[plane];
> - struct vb2_plane *psrc = >planes[plane];
> -
> - pdst->bytesused = psrc->bytesused;
> - pdst->length = psrc->length;
> - if (q->memory == VB2_MEMORY_MMAP)
> - pdst->m.mem_offset = psrc->m.offset;
> - else if (q->memory == VB2_MEMORY_USERPTR)
> - pdst->m.userptr = psrc->m.userptr;
> - else if (q->memory == VB2_MEMORY_DMABUF)
> - pdst->m.fd = psrc->m.fd;
> - pdst->data_offset = psrc->data_offset;
> - memset(pdst->reserved, 0, sizeof(pdst->reserved));
> - }
> - } else {
> - /*
> -  * We use length and offset in v4l2_planes array even for
> -  * single-planar buffers, but userspace does not.
> -  */
> - b->length = vb->planes[0].length;
> - b->bytesused = vb->planes[0].bytesused;
> - if (q->memory == VB2_MEMORY_MMAP)
> - b->m.offset = vb->planes[0].m.offset;
> - else if (q->memory == VB2_MEMORY_USERPTR)
> - b->m.userptr = vb->planes[0].m.userptr;
> - else if (q->memory == VB2_MEMORY_DMABUF)
> - b->m.fd = vb->planes[0].m.fd;
> - }
> -
> - /*
> -  * Clear any buffer state related flags.
> -  */
> - b->flags &= ~V4L2_BUFFER_MASK_FLAGS;
> - b->flags |= q->timestamp_flags & V4L2_BUF_FLAG_TIMESTAMP_MASK;
> - if (!q->copy_timestamp) {
> - /*
> -  * For non-COPY timestamps, drop timestamp source bits
> -  * and obtain the timestamp source from the queue.
> -  */
> - b->flags &= ~V4L2_BUF_FLAG_TSTAMP_SRC_MASK;
> - b->flags |= q->timestamp_flags & V4L2_BUF_FLAG_TSTAMP_SRC_MASK;
> - }
> -
> - switch (vb->state) {
> - case VB2_BUF_STATE_QUEUED:
> - case VB2_BUF_STATE_ACTIVE:
> - b->flags |= 

[PATCHv18 17/35] videobuf2-v4l2: move __fill_v4l2_buffer() function

2018-08-14 Thread Hans Verkuil
From: Hans Verkuil 

Move the __fill_v4l2_buffer() to before the vb2_queue_or_prepare_buf()
function to prepare for the next two patches.

No other changes.

Signed-off-by: Hans Verkuil 
---
 .../media/common/videobuf2/videobuf2-v4l2.c   | 264 +-
 1 file changed, 132 insertions(+), 132 deletions(-)

diff --git a/drivers/media/common/videobuf2/videobuf2-v4l2.c 
b/drivers/media/common/videobuf2/videobuf2-v4l2.c
index 886a2d8d5c6c..408fd7ce9c09 100644
--- a/drivers/media/common/videobuf2/videobuf2-v4l2.c
+++ b/drivers/media/common/videobuf2/videobuf2-v4l2.c
@@ -154,138 +154,6 @@ static void vb2_warn_zero_bytesused(struct vb2_buffer *vb)
pr_warn("use the actual size instead.\n");
 }
 
-static int vb2_queue_or_prepare_buf(struct vb2_queue *q, struct v4l2_buffer *b,
-   const char *opname)
-{
-   if (b->type != q->type) {
-   dprintk(1, "%s: invalid buffer type\n", opname);
-   return -EINVAL;
-   }
-
-   if (b->index >= q->num_buffers) {
-   dprintk(1, "%s: buffer index out of range\n", opname);
-   return -EINVAL;
-   }
-
-   if (q->bufs[b->index] == NULL) {
-   /* Should never happen */
-   dprintk(1, "%s: buffer is NULL\n", opname);
-   return -EINVAL;
-   }
-
-   if (b->memory != q->memory) {
-   dprintk(1, "%s: invalid memory type\n", opname);
-   return -EINVAL;
-   }
-
-   return __verify_planes_array(q->bufs[b->index], b);
-}
-
-/*
- * __fill_v4l2_buffer() - fill in a struct v4l2_buffer with information to be
- * returned to userspace
- */
-static void __fill_v4l2_buffer(struct vb2_buffer *vb, void *pb)
-{
-   struct v4l2_buffer *b = pb;
-   struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
-   struct vb2_queue *q = vb->vb2_queue;
-   unsigned int plane;
-
-   /* Copy back data such as timestamp, flags, etc. */
-   b->index = vb->index;
-   b->type = vb->type;
-   b->memory = vb->memory;
-   b->bytesused = 0;
-
-   b->flags = vbuf->flags;
-   b->field = vbuf->field;
-   b->timestamp = ns_to_timeval(vb->timestamp);
-   b->timecode = vbuf->timecode;
-   b->sequence = vbuf->sequence;
-   b->reserved2 = 0;
-   b->reserved = 0;
-
-   if (q->is_multiplanar) {
-   /*
-* Fill in plane-related data if userspace provided an array
-* for it. The caller has already verified memory and size.
-*/
-   b->length = vb->num_planes;
-   for (plane = 0; plane < vb->num_planes; ++plane) {
-   struct v4l2_plane *pdst = >m.planes[plane];
-   struct vb2_plane *psrc = >planes[plane];
-
-   pdst->bytesused = psrc->bytesused;
-   pdst->length = psrc->length;
-   if (q->memory == VB2_MEMORY_MMAP)
-   pdst->m.mem_offset = psrc->m.offset;
-   else if (q->memory == VB2_MEMORY_USERPTR)
-   pdst->m.userptr = psrc->m.userptr;
-   else if (q->memory == VB2_MEMORY_DMABUF)
-   pdst->m.fd = psrc->m.fd;
-   pdst->data_offset = psrc->data_offset;
-   memset(pdst->reserved, 0, sizeof(pdst->reserved));
-   }
-   } else {
-   /*
-* We use length and offset in v4l2_planes array even for
-* single-planar buffers, but userspace does not.
-*/
-   b->length = vb->planes[0].length;
-   b->bytesused = vb->planes[0].bytesused;
-   if (q->memory == VB2_MEMORY_MMAP)
-   b->m.offset = vb->planes[0].m.offset;
-   else if (q->memory == VB2_MEMORY_USERPTR)
-   b->m.userptr = vb->planes[0].m.userptr;
-   else if (q->memory == VB2_MEMORY_DMABUF)
-   b->m.fd = vb->planes[0].m.fd;
-   }
-
-   /*
-* Clear any buffer state related flags.
-*/
-   b->flags &= ~V4L2_BUFFER_MASK_FLAGS;
-   b->flags |= q->timestamp_flags & V4L2_BUF_FLAG_TIMESTAMP_MASK;
-   if (!q->copy_timestamp) {
-   /*
-* For non-COPY timestamps, drop timestamp source bits
-* and obtain the timestamp source from the queue.
-*/
-   b->flags &= ~V4L2_BUF_FLAG_TSTAMP_SRC_MASK;
-   b->flags |= q->timestamp_flags & V4L2_BUF_FLAG_TSTAMP_SRC_MASK;
-   }
-
-   switch (vb->state) {
-   case VB2_BUF_STATE_QUEUED:
-   case VB2_BUF_STATE_ACTIVE:
-   b->flags |= V4L2_BUF_FLAG_QUEUED;
-   break;
-   case VB2_BUF_STATE_ERROR:
-   b->flags |= V4L2_BUF_FLAG_ERROR;
-   /* fall through */
-   case VB2_BUF_STATE_DONE:
-