Skip to contentSkip to conversation

media: vb2: introduce queue_info

RFC PATCH New Hans Verkuil 1 participant 3 messages Oct 31, 2024

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover media: vb2: introduce queue_info

The vb2 queue_setup function is very confusing since it is used for both VIDIOC_REQBUFS and VIDIOC_CREATE_BUFS. Drivers often implement this incorrectly.

This short series adds a new queue_info callback to use as a replacement of queue_setup.

The queue_info callback just returns the number of planes and plane sizes of the current format (and optionally the devices to use to allocate each plane).

After that vb2 uses that information to deal with everything else. This means that drivers that use queue_info can no longer fiddle with the number of buffers the caller wants to allocate. This is entirely controlled by q->min_queued_buffers and q->min_reqbufs_allocation.

It makes both the vb2 code and the driver code much simpler.

The first patch makes the vb2 changes, and the second patch converts the vivid driver to the new queue_info.

Comments are very welcome.

Regards,

Hans

Hans Verkuil (2):
media: vb2: introduce queue_info to replace queue_setup
media: vivid: convert queue_setup to queue_info

 .../media/common/videobuf2/videobuf2-core.c   | 82 ++++++++++++++-----
 .../media/test-drivers/vivid/vivid-meta-cap.c | 17 ++--
 .../media/test-drivers/vivid/vivid-meta-out.c | 27 +++---
 .../media/test-drivers/vivid/vivid-sdr-cap.c  | 16 ++--
 .../test-drivers/vivid/vivid-touch-cap.c      | 18 ++--
 .../media/test-drivers/vivid/vivid-vbi-cap.c  | 13 ++-
 .../media/test-drivers/vivid/vivid-vbi-out.c  | 13 ++-
 .../media/test-drivers/vivid/vivid-vid-cap.c  | 39 +++------
 .../media/test-drivers/vivid/vivid-vid-out.c  | 37 ++-------
 include/media/videobuf2-core.h                | 10 +++
 10 files changed, 126 insertions(+), 146 deletions(-)
Signature · 1 line
2.45.2
#1 lore raw

RFC PATCH 1/2 media: vb2: introduce queue_info to replace queue_setup

The new queue_info just returns the number of planes and plane sizes for the currently configured format.

---
 .../media/common/videobuf2/videobuf2-core.c   | 82 ++++++++++++++-----
 include/media/videobuf2-core.h                | 10 +++
 2 files changed, 70 insertions(+), 22 deletions(-)
drivers/media/common/videobuf2/videobuf2-core.c +60 -22
index f07dc53a9d06..3a7303a72202 100644
@@ -611,9 +611,9 @@ static void __vb2_queue_free(struct vb2_queue *q, unsigned int start, unsigned i
 		if (unbalanced) {
 			pr_info("unbalanced counters for queue %p:\n", q);
 			if (q->cnt_start_streaming != q->cnt_stop_streaming)
-				pr_info("     setup: %u start_streaming: %u stop_streaming: %u\n",
-					q->cnt_queue_setup, q->cnt_start_streaming,
-					q->cnt_stop_streaming);
+				pr_info("     setup: %u info: %u start_streaming: %u stop_streaming: %u\n",
+					q->cnt_queue_setup, q->cnt_queue_info,
+					q->cnt_start_streaming, q->cnt_stop_streaming);
 			if (q->cnt_prepare_streaming != q->cnt_unprepare_streaming)
 				pr_info("     prepare_streaming: %u unprepare_streaming: %u\n",
 					q->cnt_prepare_streaming, q->cnt_unprepare_streaming);
@@ -622,6 +622,7 @@ static void __vb2_queue_free(struct vb2_queue *q, unsigned int start, unsigned i
 					q->cnt_wait_prepare, q->cnt_wait_finish);
 		}
 		q->cnt_queue_setup = 0;
+		q->cnt_queue_info = 0;
 		q->cnt_wait_prepare = 0;
 		q->cnt_wait_finish = 0;
 		q->cnt_prepare_streaming = 0;
@@ -914,7 +915,8 @@ int vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory,
 		q->is_busy = 0;
 		/*
 		 * In case of REQBUFS(0) return immediately without calling
-		 * driver's queue_setup() callback and allocating resources.
+		 * driver's queue_setup() or queue_info() callback and
+		 * allocating resources.
 		 */
 		if (*count == 0)
 			return 0;
@@ -928,7 +930,7 @@ int vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory,
 	memset(q->alloc_devs, 0, sizeof(q->alloc_devs));
 	/*
 	 * Set this now to ensure that drivers see the correct q->memory value
-	 * in the queue_setup op.
+	 * in the queue_setup/info op.
 	 */
 	mutex_lock(&q->mmap_lock);
 	ret = vb2_core_allocated_buffers_storage(q);
@@ -938,12 +940,18 @@ int vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory,
 		return ret;
 	set_queue_coherency(q, non_coherent_mem);
 
-	/*
-	 * Ask the driver how many buffers and planes per buffer it requires.
-	 * Driver also sets the size and allocator context for each plane.
-	 */
-	ret = call_qop(q, queue_setup, q, &num_buffers, &num_planes,
-		       plane_sizes, q->alloc_devs);
+	if (q->ops->queue_info) {
+		ret = call_qop(q, queue_info, q, &num_planes,
+			       plane_sizes, q->alloc_devs);
+	} else {
+		/*
+		 * Ask the driver how many buffers and planes per buffer it
+		 * requires. The driver also sets the size and (optionally)
+		 * the allocator context for each plane.
+		 */
+		ret = call_qop(q, queue_setup, q, &num_buffers, &num_planes,
+			       plane_sizes, q->alloc_devs);
+	}
 	if (ret)
 		goto error;
 
@@ -980,7 +988,7 @@ int vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory,
 	/*
 	 * Check if driver can handle the allocated number of buffers.
 	 */
-	if (!ret && allocated_buffers < num_buffers) {
+	if (!ret && allocated_buffers < num_buffers && q->ops->queue_setup) {
 		num_buffers = allocated_buffers;
 		/*
 		 * num_planes is set by the previous queue_setup(), but since it
@@ -1082,17 +1090,44 @@ int vb2_core_create_bufs(struct vb2_queue *q, enum vb2_memory memory,
 
 	num_buffers = min(*count, q->max_num_buffers - q_num_bufs);
 
-	if (requested_planes && requested_sizes) {
+	if (q->ops->queue_info) {
+		ret = call_qop(q, queue_info, q, &num_planes,
+			       plane_sizes, q->alloc_devs);
+
+		if (ret)
+			goto error;
+
+		/* Check that driver has set sane values */
+		if (WARN_ON(!num_planes)) {
+			ret = -EINVAL;
+			goto error;
+		}
+		if (num_planes != requested_planes) {
+			ret = -EINVAL;
+			goto error;
+		}
+
+		for (unsigned int i = 0; i < num_planes; i++) {
+			if (WARN_ON(!plane_sizes[i])) {
+				ret = -EINVAL;
+				goto error;
+			}
+			if (plane_sizes[i] > requested_sizes[i]) {
+				ret = -EINVAL;
+				goto error;
+			}
+			plane_sizes[i] = requested_sizes[i];
+		}
+	} else {
 		num_planes = requested_planes;
 		memcpy(plane_sizes, requested_sizes, sizeof(plane_sizes));
+		/*
+		 * Ask the driver, whether the requested number of buffers, planes per
+		 * buffer and their sizes are acceptable
+		 */
+		ret = call_qop(q, queue_setup, q, &num_buffers,
+			       &num_planes, plane_sizes, q->alloc_devs);
 	}
-
-	/*
-	 * Ask the driver, whether the requested number of buffers, planes per
-	 * buffer and their sizes are acceptable
-	 */
-	ret = call_qop(q, queue_setup, q, &num_buffers,
-		       &num_planes, plane_sizes, q->alloc_devs);
 	if (ret)
 		goto error;
 
@@ -1108,7 +1143,7 @@ int vb2_core_create_bufs(struct vb2_queue *q, enum vb2_memory memory,
 	/*
 	 * Check if driver can handle the so far allocated number of buffers.
 	 */
-	if (allocated_buffers < num_buffers) {
+	if (allocated_buffers < num_buffers && q->ops->queue_setup) {
 		num_buffers = allocated_buffers;
 
 		/*
@@ -2617,10 +2652,13 @@ int vb2_core_queue_init(struct vb2_queue *q)
 	    WARN_ON(!q->mem_ops)	  ||
 	    WARN_ON(!q->type)		  ||
 	    WARN_ON(!q->io_modes)	  ||
-	    WARN_ON(!q->ops->queue_setup) ||
 	    WARN_ON(!q->ops->buf_queue))
 		return -EINVAL;
 
+	if (WARN_ON(!q->ops->queue_setup && !q->ops->queue_info) ||
+	    WARN_ON(q->ops->queue_setup && q->ops->queue_info))
+		return -EINVAL;
+
 	if (WARN_ON(q->max_num_buffers < VB2_MAX_FRAME) ||
 	    WARN_ON(q->min_queued_buffers > q->max_num_buffers))
 		return -EINVAL;
include/media/videobuf2-core.h +10 -0
index 9b02aeba4108..34b6fd6585b9 100644
@@ -351,6 +351,13 @@ struct vb2_buffer {
  *			\*num_buffers are being allocated additionally to
  *			the buffers already allocated. If either \*num_planes
  *			or the requested sizes are invalid callback must return %-EINVAL.
+ * @queue_info:		called from VIDIOC_REQBUFS() and VIDIOC_CREATE_BUFS()
+ *			handlers before memory allocation.
+ *			The driver must return the required number of planes
+ *			per buffer in \*num_planes, and the size of each plane
+ *			must be set in the sizes\[\] array. Optionally set the
+ *			per-plane allocator specific device in the
+ *			alloc_devs\[\] array.
  * @wait_prepare:	release any locks taken while calling vb2 functions;
  *			it is called before an ioctl needs to wait for a new
  *			buffer to arrive; required to avoid a deadlock in
@@ -435,6 +442,8 @@ struct vb2_ops {
 	int (*queue_setup)(struct vb2_queue *q,
 			   unsigned int *num_buffers, unsigned int *num_planes,
 			   unsigned int sizes[], struct device *alloc_devs[]);
+	int (*queue_info)(struct vb2_queue *q, unsigned int *num_planes,
+			  unsigned int sizes[], struct device *alloc_devs[]);
 
 	void (*wait_prepare)(struct vb2_queue *q);
 	void (*wait_finish)(struct vb2_queue *q);
@@ -680,6 +689,7 @@ struct vb2_queue {
 	 * called. Used to check for unbalanced ops.
 	 */
 	u32				cnt_queue_setup;
+	u32				cnt_queue_info;
 	u32				cnt_wait_prepare;
 	u32				cnt_wait_finish;
 	u32				cnt_prepare_streaming;
Signature · 1 line
2.45.2
#2 lore raw

RFC PATCH 2/2 media: vivid: convert queue_setup to queue_info

In reply to Hans Verkuil

Use the new queue_info callback instead of queue_setup.

---
 .../media/test-drivers/vivid/vivid-meta-cap.c | 17 +++-----
 .../media/test-drivers/vivid/vivid-meta-out.c | 27 +++++--------
 .../media/test-drivers/vivid/vivid-sdr-cap.c  | 16 +++-----
 .../test-drivers/vivid/vivid-touch-cap.c      | 18 +++------
 .../media/test-drivers/vivid/vivid-vbi-cap.c  | 13 +++----
 .../media/test-drivers/vivid/vivid-vbi-out.c  | 13 +++----
 .../media/test-drivers/vivid/vivid-vid-cap.c  | 39 ++++++-------------
 .../media/test-drivers/vivid/vivid-vid-out.c  | 37 +++++-------------
 8 files changed, 56 insertions(+), 124 deletions(-)
drivers/media/test-drivers/vivid/vivid-meta-cap.c +5 -12
index c7aaecc0b5a2..90d3f6d74a21 100644
@@ -13,24 +13,17 @@
 #include "vivid-kthread-cap.h"
 #include "vivid-meta-cap.h"
 
-static int meta_cap_queue_setup(struct vb2_queue *vq, unsigned int *nbuffers,
-				unsigned int *nplanes, unsigned int sizes[],
-				struct device *alloc_devs[])
+static int meta_cap_queue_info(struct vb2_queue *vq,
+			       unsigned int *nplanes, unsigned int sizes[],
+			       struct device *alloc_devs[])
 {
 	struct vivid_dev *dev = vb2_get_drv_priv(vq);
-	unsigned int size =  sizeof(struct vivid_uvc_meta_buf);
 
 	if (!vivid_is_webcam(dev))
 		return -EINVAL;
 
-	if (*nplanes) {
-		if (sizes[0] < size)
-			return -EINVAL;
-	} else {
-		sizes[0] = size;
-	}
-
 	*nplanes = 1;
+	sizes[0] = sizeof(struct vivid_uvc_meta_buf);
 	return 0;
 }
 
@@ -116,7 +109,7 @@ static void meta_cap_buf_request_complete(struct vb2_buffer *vb)
 }
 
 const struct vb2_ops vivid_meta_cap_qops = {
-	.queue_setup		= meta_cap_queue_setup,
+	.queue_info		= meta_cap_queue_info,
 	.buf_prepare		= meta_cap_buf_prepare,
 	.buf_queue		= meta_cap_buf_queue,
 	.start_streaming	= meta_cap_start_streaming,
drivers/media/test-drivers/vivid/vivid-meta-out.c +10 -17
index 55e5e5dec2f2..432b0f6317bc 100644
@@ -13,24 +13,17 @@
 #include "vivid-kthread-out.h"
 #include "vivid-meta-out.h"
 
-static int meta_out_queue_setup(struct vb2_queue *vq, unsigned int *nbuffers,
-				unsigned int *nplanes, unsigned int sizes[],
-				struct device *alloc_devs[])
+static int meta_out_queue_info(struct vb2_queue *vq,
+			       unsigned int *nplanes, unsigned int sizes[],
+			       struct device *alloc_devs[])
 {
 	struct vivid_dev *dev = vb2_get_drv_priv(vq);
-	unsigned int size =  sizeof(struct vivid_meta_out_buf);
 
 	if (!vivid_is_webcam(dev))
 		return -EINVAL;
 
-	if (*nplanes) {
-		if (sizes[0] < size)
-			return -EINVAL;
-	} else {
-		sizes[0] = size;
-	}
-
 	*nplanes = 1;
+	sizes[0] = sizeof(struct vivid_meta_out_buf);
 	return 0;
 }
 
@@ -116,12 +109,12 @@ static void meta_out_buf_request_complete(struct vb2_buffer *vb)
 }
 
 const struct vb2_ops vivid_meta_out_qops = {
-	.queue_setup            = meta_out_queue_setup,
-	.buf_prepare            = meta_out_buf_prepare,
-	.buf_queue              = meta_out_buf_queue,
-	.start_streaming        = meta_out_start_streaming,
-	.stop_streaming         = meta_out_stop_streaming,
-	.buf_request_complete   = meta_out_buf_request_complete,
+	.queue_info		= meta_out_queue_info,
+	.buf_prepare		= meta_out_buf_prepare,
+	.buf_queue		= meta_out_buf_queue,
+	.start_streaming	= meta_out_start_streaming,
+	.stop_streaming		= meta_out_stop_streaming,
+	.buf_request_complete	= meta_out_buf_request_complete,
 };
 
 int vidioc_enum_fmt_meta_out(struct file *file, void  *priv,
drivers/media/test-drivers/vivid/vivid-sdr-cap.c +6 -10
index 74a91d28c8be..ee94dcfb62f2 100644
@@ -214,18 +214,14 @@ static int vivid_thread_sdr_cap(void *data)
 	return 0;
 }
 
-static int sdr_cap_queue_setup(struct vb2_queue *vq,
-		       unsigned *nbuffers, unsigned *nplanes,
-		       unsigned sizes[], struct device *alloc_devs[])
+static int sdr_cap_queue_info(struct vb2_queue *vq,
+			      unsigned int *nplanes, unsigned int sizes[],
+			      struct device *alloc_devs[])
 {
-	/* 2 = max 16-bit sample returned */
-	u32 size = SDR_CAP_SAMPLES_PER_BUF * 2;
-
-	if (*nplanes)
-		return sizes[0] < size ? -EINVAL : 0;
 
 	*nplanes = 1;
-	sizes[0] = size;
+	/* 2 = max 16-bit sample returned */
+	sizes[0] = SDR_CAP_SAMPLES_PER_BUF * 2;
 	return 0;
 }
 
@@ -331,7 +327,7 @@ static void sdr_cap_buf_request_complete(struct vb2_buffer *vb)
 }
 
 const struct vb2_ops vivid_sdr_cap_qops = {
-	.queue_setup		= sdr_cap_queue_setup,
+	.queue_info		= sdr_cap_queue_info,
 	.buf_prepare		= sdr_cap_buf_prepare,
 	.buf_queue		= sdr_cap_buf_queue,
 	.start_streaming	= sdr_cap_start_streaming,
drivers/media/test-drivers/vivid/vivid-touch-cap.c +5 -13
index 36a781fa17bc..49824674d0e9 100644
@@ -8,22 +8,14 @@
 #include "vivid-vid-common.h"
 #include "vivid-touch-cap.h"
 
-static int touch_cap_queue_setup(struct vb2_queue *vq, unsigned int *nbuffers,
-				 unsigned int *nplanes, unsigned int sizes[],
-				 struct device *alloc_devs[])
+static int touch_cap_queue_info(struct vb2_queue *vq,
+				unsigned int *nplanes, unsigned int sizes[],
+				struct device *alloc_devs[])
 {
 	struct vivid_dev *dev = vb2_get_drv_priv(vq);
-	struct v4l2_pix_format *f = &dev->tch_format;
-	unsigned int size = f->sizeimage;
-
-	if (*nplanes) {
-		if (*nplanes != 1)
-			return -EINVAL;
-		return sizes[0] < size ? -EINVAL : 0;
-	}
 
 	*nplanes = 1;
-	sizes[0] = size;
+	sizes[0] = dev->tch_format.sizeimage;
 	return 0;
 }
 
@@ -104,7 +96,7 @@ static void touch_cap_buf_request_complete(struct vb2_buffer *vb)
 }
 
 const struct vb2_ops vivid_touch_cap_qops = {
-	.queue_setup		= touch_cap_queue_setup,
+	.queue_info		= touch_cap_queue_info,
 	.buf_prepare		= touch_cap_buf_prepare,
 	.buf_queue		= touch_cap_buf_queue,
 	.start_streaming	= touch_cap_start_streaming,
drivers/media/test-drivers/vivid/vivid-vbi-cap.c +5 -8
index a09f62c66c33..8d9696d5800a 100644
@@ -120,9 +120,9 @@ void vivid_sliced_vbi_cap_process(struct vivid_dev *dev,
 	}
 }
 
-static int vbi_cap_queue_setup(struct vb2_queue *vq,
-		       unsigned *nbuffers, unsigned *nplanes,
-		       unsigned sizes[], struct device *alloc_devs[])
+static int vbi_cap_queue_info(struct vb2_queue *vq,
+			      unsigned int *nplanes, unsigned int sizes[],
+			      struct device *alloc_devs[])
 {
 	struct vivid_dev *dev = vb2_get_drv_priv(vq);
 	bool is_60hz = dev->std_cap[dev->input] & V4L2_STD_525_60;
@@ -133,11 +133,8 @@ static int vbi_cap_queue_setup(struct vb2_queue *vq,
 	if (!vivid_is_sdtv_cap(dev))
 		return -EINVAL;
 
-	if (*nplanes)
-		return sizes[0] < size ? -EINVAL : 0;
-	sizes[0] = size;
-
 	*nplanes = 1;
+	sizes[0] = size;
 	return 0;
 }
 
@@ -224,7 +221,7 @@ static void vbi_cap_buf_request_complete(struct vb2_buffer *vb)
 }
 
 const struct vb2_ops vivid_vbi_cap_qops = {
-	.queue_setup		= vbi_cap_queue_setup,
+	.queue_info		= vbi_cap_queue_info,
 	.buf_prepare		= vbi_cap_buf_prepare,
 	.buf_queue		= vbi_cap_buf_queue,
 	.start_streaming	= vbi_cap_start_streaming,
drivers/media/test-drivers/vivid/vivid-vbi-out.c +5 -8
index b7a09d2f394e..99a5843e210a 100644
@@ -15,9 +15,9 @@
 #include "vivid-vbi-out.h"
 #include "vivid-vbi-cap.h"
 
-static int vbi_out_queue_setup(struct vb2_queue *vq,
-		       unsigned *nbuffers, unsigned *nplanes,
-		       unsigned sizes[], struct device *alloc_devs[])
+static int vbi_out_queue_info(struct vb2_queue *vq,
+			      unsigned int *nplanes, unsigned int sizes[],
+			      struct device *alloc_devs[])
 {
 	struct vivid_dev *dev = vb2_get_drv_priv(vq);
 	bool is_60hz = dev->std_out & V4L2_STD_525_60;
@@ -28,11 +28,8 @@ static int vbi_out_queue_setup(struct vb2_queue *vq,
 	if (!vivid_is_svid_out(dev))
 		return -EINVAL;
 
-	if (*nplanes)
-		return sizes[0] < size ? -EINVAL : 0;
-	sizes[0] = size;
-
 	*nplanes = 1;
+	sizes[0] = size;
 	return 0;
 }
 
@@ -122,7 +119,7 @@ static void vbi_out_buf_request_complete(struct vb2_buffer *vb)
 }
 
 const struct vb2_ops vivid_vbi_out_qops = {
-	.queue_setup		= vbi_out_queue_setup,
+	.queue_info		= vbi_out_queue_info,
 	.buf_prepare		= vbi_out_buf_prepare,
 	.buf_queue		= vbi_out_buf_queue,
 	.start_streaming	= vbi_out_start_streaming,
drivers/media/test-drivers/vivid/vivid-vid-cap.c +11 -28
index ecff984e521c..5e08d79618f5 100644
@@ -72,12 +72,12 @@ static inline unsigned int webcam_ival_count(const struct vivid_dev *dev,
 	return ARRAY_SIZE(webcam_intervals);
 }
 
-static int vid_cap_queue_setup(struct vb2_queue *vq,
-		       unsigned *nbuffers, unsigned *nplanes,
-		       unsigned sizes[], struct device *alloc_devs[])
+static int vid_cap_queue_info(struct vb2_queue *vq,
+			      unsigned int *nplanes, unsigned int sizes[],
+			      struct device *alloc_devs[])
 {
 	struct vivid_dev *dev = vb2_get_drv_priv(vq);
-	unsigned buffers = tpg_g_buffers(&dev->tpg);
+	unsigned planes = tpg_g_buffers(&dev->tpg);
 	unsigned h = dev->fmt_cap_rect.height;
 	unsigned p;
 
@@ -98,30 +98,13 @@ static int vid_cap_queue_setup(struct vb2_queue *vq,
 		dev->queue_setup_error = false;
 		return -EINVAL;
 	}
-	if (*nplanes) {
-		/*
-		 * Check if the number of requested planes match
-		 * the number of buffers in the current format. You can't mix that.
-		 */
-		if (*nplanes != buffers)
-			return -EINVAL;
-		for (p = 0; p < buffers; p++) {
-			if (sizes[p] < tpg_g_line_width(&dev->tpg, p) * h /
-					dev->fmt_cap->vdownsampling[p] +
-					dev->fmt_cap->data_offset[p])
-				return -EINVAL;
-		}
-	} else {
-		for (p = 0; p < buffers; p++)
-			sizes[p] = (tpg_g_line_width(&dev->tpg, p) * h) /
-					dev->fmt_cap->vdownsampling[p] +
-					dev->fmt_cap->data_offset[p];
-	}
+	*nplanes = planes;
+	for (p = 0; p < planes; p++)
+		sizes[p] = (tpg_g_line_width(&dev->tpg, p) * h) /
+			dev->fmt_cap->vdownsampling[p] +
+			dev->fmt_cap->data_offset[p];
 
-	*nplanes = buffers;
-
-	dprintk(dev, 1, "%s: count=%d\n", __func__, *nbuffers);
-	for (p = 0; p < buffers; p++)
+	for (p = 0; p < planes; p++)
 		dprintk(dev, 1, "%s: size[%u]=%u\n", __func__, p, sizes[p]);
 
 	return 0;
@@ -250,7 +233,7 @@ static void vid_cap_buf_request_complete(struct vb2_buffer *vb)
 }
 
 const struct vb2_ops vivid_vid_cap_qops = {
-	.queue_setup		= vid_cap_queue_setup,
+	.queue_info		= vid_cap_queue_info,
 	.buf_prepare		= vid_cap_buf_prepare,
 	.buf_finish		= vid_cap_buf_finish,
 	.buf_queue		= vid_cap_buf_queue,
drivers/media/test-drivers/vivid/vivid-vid-out.c +9 -28
index 5ec84db934d6..b183ee1b9048 100644
@@ -20,9 +20,9 @@
 #include "vivid-kthread-out.h"
 #include "vivid-vid-out.h"
 
-static int vid_out_queue_setup(struct vb2_queue *vq,
-		       unsigned *nbuffers, unsigned *nplanes,
-		       unsigned sizes[], struct device *alloc_devs[])
+static int vid_out_queue_info(struct vb2_queue *vq,
+			      unsigned int *nplanes, unsigned int sizes[],
+			      struct device *alloc_devs[])
 {
 	struct vivid_dev *dev = vb2_get_drv_priv(vq);
 	const struct vivid_fmt *vfmt = dev->fmt_out;
@@ -53,31 +53,12 @@ static int vid_out_queue_setup(struct vb2_queue *vq,
 		return -EINVAL;
 	}
 
-	if (*nplanes) {
-		/*
-		 * Check if the number of requested planes match
-		 * the number of planes in the current format. You can't mix that.
-		 */
-		if (*nplanes != planes)
-			return -EINVAL;
-		if (sizes[0] < size)
-			return -EINVAL;
-		for (p = 1; p < planes; p++) {
-			if (sizes[p] < dev->bytesperline_out[p] * h /
-					vfmt->vdownsampling[p] +
-					vfmt->data_offset[p])
-				return -EINVAL;
-		}
-	} else {
-		for (p = 0; p < planes; p++)
-			sizes[p] = p ? dev->bytesperline_out[p] * h /
-					vfmt->vdownsampling[p] +
-					vfmt->data_offset[p] : size;
-	}
-
 	*nplanes = planes;
+	for (p = 0; p < planes; p++)
+		sizes[p] = p ? dev->bytesperline_out[p] * h /
+			vfmt->vdownsampling[p] +
+			vfmt->data_offset[p] : size;
 
-	dprintk(dev, 1, "%s: count=%u\n", __func__, *nbuffers);
 	for (p = 0; p < planes; p++)
 		dprintk(dev, 1, "%s: size[%u]=%u\n", __func__, p, sizes[p]);
 	return 0;
@@ -194,8 +175,8 @@ static void vid_out_buf_request_complete(struct vb2_buffer *vb)
 }
 
 const struct vb2_ops vivid_vid_out_qops = {
-	.queue_setup		= vid_out_queue_setup,
-	.buf_out_validate		= vid_out_buf_out_validate,
+	.queue_info		= vid_out_queue_info,
+	.buf_out_validate	= vid_out_buf_out_validate,
 	.buf_prepare		= vid_out_buf_prepare,
 	.buf_queue		= vid_out_buf_queue,
 	.start_streaming	= vid_out_start_streaming,
Signature · 1 line
2.45.2