Commit 412376a1 authored by Hans Verkuil's avatar Hans Verkuil Committed by Mauro Carvalho Chehab

[media] vb2: fix handling of data_offset and v4l2_plane.reserved[]

The videobuf2-core did not zero the 'planes' array in __qbuf_userptr()
and __qbuf_dmabuf(). That's now memset to 0. Without this the reserved
array in struct v4l2_plane would be non-zero, causing v4l2-compliance
errors.

More serious is the fact that data_offset was not handled correctly:

- for capture devices it was never zeroed, which meant that it was
  uninitialized. Unless the driver sets it it was a completely random
  number. With the memset above this is now fixed.

- __qbuf_dmabuf had a completely incorrect length check that included
  data_offset.

- in __fill_vb2_buffer in the DMABUF case the data_offset field was
  unconditionally copied from v4l2_buffer to v4l2_plane when this
  should only happen in the output case.

- in the single-planar case data_offset was never correctly set to 0.
  The single-planar API doesn't support data_offset, so setting it
  to 0 is the right thing to do. This too is now solved by the memset.

All these issues were found with v4l2-compliance.
Signed-off-by: default avatarHans Verkuil <hans.verkuil@cisco.com>
Acked-by: default avatarPawel Osciak <pawel@osciak.com>
Acked-by: default avatarSakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: default avatarMauro Carvalho Chehab <m.chehab@samsung.com>
parent bc96f30c
...@@ -1234,8 +1234,6 @@ static void __fill_vb2_buffer(struct vb2_buffer *vb, const struct v4l2_buffer *b ...@@ -1234,8 +1234,6 @@ static void __fill_vb2_buffer(struct vb2_buffer *vb, const struct v4l2_buffer *b
b->m.planes[plane].m.fd; b->m.planes[plane].m.fd;
v4l2_planes[plane].length = v4l2_planes[plane].length =
b->m.planes[plane].length; b->m.planes[plane].length;
v4l2_planes[plane].data_offset =
b->m.planes[plane].data_offset;
} }
} }
} else { } else {
...@@ -1245,10 +1243,8 @@ static void __fill_vb2_buffer(struct vb2_buffer *vb, const struct v4l2_buffer *b ...@@ -1245,10 +1243,8 @@ static void __fill_vb2_buffer(struct vb2_buffer *vb, const struct v4l2_buffer *b
* In videobuf we use our internal V4l2_planes struct for * In videobuf we use our internal V4l2_planes struct for
* single-planar buffers as well, for simplicity. * single-planar buffers as well, for simplicity.
*/ */
if (V4L2_TYPE_IS_OUTPUT(b->type)) { if (V4L2_TYPE_IS_OUTPUT(b->type))
v4l2_planes[0].bytesused = b->bytesused; v4l2_planes[0].bytesused = b->bytesused;
v4l2_planes[0].data_offset = 0;
}
if (b->memory == V4L2_MEMORY_USERPTR) { if (b->memory == V4L2_MEMORY_USERPTR) {
v4l2_planes[0].m.userptr = b->m.userptr; v4l2_planes[0].m.userptr = b->m.userptr;
...@@ -1258,9 +1254,7 @@ static void __fill_vb2_buffer(struct vb2_buffer *vb, const struct v4l2_buffer *b ...@@ -1258,9 +1254,7 @@ static void __fill_vb2_buffer(struct vb2_buffer *vb, const struct v4l2_buffer *b
if (b->memory == V4L2_MEMORY_DMABUF) { if (b->memory == V4L2_MEMORY_DMABUF) {
v4l2_planes[0].m.fd = b->m.fd; v4l2_planes[0].m.fd = b->m.fd;
v4l2_planes[0].length = b->length; v4l2_planes[0].length = b->length;
v4l2_planes[0].data_offset = 0;
} }
} }
/* Zero flags that the vb2 core handles */ /* Zero flags that the vb2 core handles */
...@@ -1303,6 +1297,7 @@ static int __qbuf_userptr(struct vb2_buffer *vb, const struct v4l2_buffer *b) ...@@ -1303,6 +1297,7 @@ static int __qbuf_userptr(struct vb2_buffer *vb, const struct v4l2_buffer *b)
int write = !V4L2_TYPE_IS_OUTPUT(q->type); int write = !V4L2_TYPE_IS_OUTPUT(q->type);
bool reacquired = vb->planes[0].mem_priv == NULL; bool reacquired = vb->planes[0].mem_priv == NULL;
memset(planes, 0, sizeof(planes[0]) * vb->num_planes);
/* Copy relevant information provided by the userspace */ /* Copy relevant information provided by the userspace */
__fill_vb2_buffer(vb, b, planes); __fill_vb2_buffer(vb, b, planes);
...@@ -1414,6 +1409,7 @@ static int __qbuf_dmabuf(struct vb2_buffer *vb, const struct v4l2_buffer *b) ...@@ -1414,6 +1409,7 @@ static int __qbuf_dmabuf(struct vb2_buffer *vb, const struct v4l2_buffer *b)
int write = !V4L2_TYPE_IS_OUTPUT(q->type); int write = !V4L2_TYPE_IS_OUTPUT(q->type);
bool reacquired = vb->planes[0].mem_priv == NULL; bool reacquired = vb->planes[0].mem_priv == NULL;
memset(planes, 0, sizeof(planes[0]) * vb->num_planes);
/* Copy relevant information provided by the userspace */ /* Copy relevant information provided by the userspace */
__fill_vb2_buffer(vb, b, planes); __fill_vb2_buffer(vb, b, planes);
...@@ -1431,8 +1427,7 @@ static int __qbuf_dmabuf(struct vb2_buffer *vb, const struct v4l2_buffer *b) ...@@ -1431,8 +1427,7 @@ static int __qbuf_dmabuf(struct vb2_buffer *vb, const struct v4l2_buffer *b)
if (planes[plane].length == 0) if (planes[plane].length == 0)
planes[plane].length = dbuf->size; planes[plane].length = dbuf->size;
if (planes[plane].length < planes[plane].data_offset + if (planes[plane].length < q->plane_sizes[plane]) {
q->plane_sizes[plane]) {
dprintk(1, "qbuf: invalid dmabuf length for plane %d\n", dprintk(1, "qbuf: invalid dmabuf length for plane %d\n",
plane); plane);
ret = -EINVAL; ret = -EINVAL;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment