Skip to content

Commit b32431b

Browse files
author
Hans Verkuil
committed
media: vb2: refactor setting flags and caps, fix missing cap
Several functions implementing VIDIOC_REQBUFS and _CREATE_BUFS all use almost the same code to fill in the flags and capability fields. Refactor this into a new vb2_set_flags_and_caps() function that replaces the old fill_buf_caps() and validate_memory_flags() functions. This also fixes a bug where vb2_ioctl_create_bufs() would not set the V4L2_BUF_CAP_SUPPORTS_MAX_NUM_BUFFERS cap and also not fill in the max_num_buffers field. Fixes: d055a76 ("media: core: Report the maximum possible number of buffers for the queue") Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl> Reviewed-by: Benjamin Gaignard <benjamin.gaignard@collabora.com> Acked-by: Tomasz Figa <tfiga@chromium.org>
1 parent 78e23c3 commit b32431b

File tree

1 file changed

+25
-28
lines changed

1 file changed

+25
-28
lines changed

drivers/media/common/videobuf2/videobuf2-v4l2.c

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -671,8 +671,20 @@ int vb2_querybuf(struct vb2_queue *q, struct v4l2_buffer *b)
671671
}
672672
EXPORT_SYMBOL(vb2_querybuf);
673673

674-
static void fill_buf_caps(struct vb2_queue *q, u32 *caps)
674+
static void vb2_set_flags_and_caps(struct vb2_queue *q, u32 memory,
675+
u32 *flags, u32 *caps, u32 *max_num_bufs)
675676
{
677+
if (!q->allow_cache_hints || memory != V4L2_MEMORY_MMAP) {
678+
/*
679+
* This needs to clear V4L2_MEMORY_FLAG_NON_COHERENT only,
680+
* but in order to avoid bugs we zero out all bits.
681+
*/
682+
*flags = 0;
683+
} else {
684+
/* Clear all unknown flags. */
685+
*flags &= V4L2_MEMORY_FLAG_NON_COHERENT;
686+
}
687+
676688
*caps = V4L2_BUF_CAP_SUPPORTS_ORPHANED_BUFS;
677689
if (q->io_modes & VB2_MMAP)
678690
*caps |= V4L2_BUF_CAP_SUPPORTS_MMAP;
@@ -686,21 +698,9 @@ static void fill_buf_caps(struct vb2_queue *q, u32 *caps)
686698
*caps |= V4L2_BUF_CAP_SUPPORTS_MMAP_CACHE_HINTS;
687699
if (q->supports_requests)
688700
*caps |= V4L2_BUF_CAP_SUPPORTS_REQUESTS;
689-
}
690-
691-
static void validate_memory_flags(struct vb2_queue *q,
692-
int memory,
693-
u32 *flags)
694-
{
695-
if (!q->allow_cache_hints || memory != V4L2_MEMORY_MMAP) {
696-
/*
697-
* This needs to clear V4L2_MEMORY_FLAG_NON_COHERENT only,
698-
* but in order to avoid bugs we zero out all bits.
699-
*/
700-
*flags = 0;
701-
} else {
702-
/* Clear all unknown flags. */
703-
*flags &= V4L2_MEMORY_FLAG_NON_COHERENT;
701+
if (max_num_bufs) {
702+
*max_num_bufs = q->max_num_buffers;
703+
*caps |= V4L2_BUF_CAP_SUPPORTS_MAX_NUM_BUFFERS;
704704
}
705705
}
706706

@@ -709,8 +709,8 @@ int vb2_reqbufs(struct vb2_queue *q, struct v4l2_requestbuffers *req)
709709
int ret = vb2_verify_memory_type(q, req->memory, req->type);
710710
u32 flags = req->flags;
711711

712-
fill_buf_caps(q, &req->capabilities);
713-
validate_memory_flags(q, req->memory, &flags);
712+
vb2_set_flags_and_caps(q, req->memory, &flags,
713+
&req->capabilities, NULL);
714714
req->flags = flags;
715715
return ret ? ret : vb2_core_reqbufs(q, req->memory,
716716
req->flags, &req->count);
@@ -751,11 +751,9 @@ int vb2_create_bufs(struct vb2_queue *q, struct v4l2_create_buffers *create)
751751
int ret = vb2_verify_memory_type(q, create->memory, f->type);
752752
unsigned i;
753753

754-
fill_buf_caps(q, &create->capabilities);
755-
validate_memory_flags(q, create->memory, &create->flags);
756754
create->index = vb2_get_num_buffers(q);
757-
create->max_num_buffers = q->max_num_buffers;
758-
create->capabilities |= V4L2_BUF_CAP_SUPPORTS_MAX_NUM_BUFFERS;
755+
vb2_set_flags_and_caps(q, create->memory, &create->flags,
756+
&create->capabilities, &create->max_num_buffers);
759757
if (create->count == 0)
760758
return ret != -EBUSY ? ret : 0;
761759

@@ -1006,8 +1004,8 @@ int vb2_ioctl_reqbufs(struct file *file, void *priv,
10061004
int res = vb2_verify_memory_type(vdev->queue, p->memory, p->type);
10071005
u32 flags = p->flags;
10081006

1009-
fill_buf_caps(vdev->queue, &p->capabilities);
1010-
validate_memory_flags(vdev->queue, p->memory, &flags);
1007+
vb2_set_flags_and_caps(vdev->queue, p->memory, &flags,
1008+
&p->capabilities, NULL);
10111009
p->flags = flags;
10121010
if (res)
10131011
return res;
@@ -1026,12 +1024,11 @@ int vb2_ioctl_create_bufs(struct file *file, void *priv,
10261024
struct v4l2_create_buffers *p)
10271025
{
10281026
struct video_device *vdev = video_devdata(file);
1029-
int res = vb2_verify_memory_type(vdev->queue, p->memory,
1030-
p->format.type);
1027+
int res = vb2_verify_memory_type(vdev->queue, p->memory, p->format.type);
10311028

10321029
p->index = vb2_get_num_buffers(vdev->queue);
1033-
fill_buf_caps(vdev->queue, &p->capabilities);
1034-
validate_memory_flags(vdev->queue, p->memory, &p->flags);
1030+
vb2_set_flags_and_caps(vdev->queue, p->memory, &p->flags,
1031+
&p->capabilities, &p->max_num_buffers);
10351032
/*
10361033
* If count == 0, then just check if memory and type are valid.
10371034
* Any -EBUSY result from vb2_verify_memory_type can be mapped to 0.

0 commit comments

Comments
 (0)