diff mbox series

[RFC,PATCHv2,07/11] videobuf2-v4l2.c: vb2_request_validate: support RO requests

Message ID 20210610113615.785359-8-hverkuil-cisco@xs4all.nl
State New
Headers show
Series Dynamic arrays and read-only requests | expand

Commit Message

Hans Verkuil June 10, 2021, 11:36 a.m. UTC
If the vb2_queue for which the request is validated only supports
read-only requests, then check if non-buffer objects are in the
request and return -EINVAL if that is the case.

Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
---
 .../media/common/videobuf2/videobuf2-v4l2.c   | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/drivers/media/common/videobuf2/videobuf2-v4l2.c b/drivers/media/common/videobuf2/videobuf2-v4l2.c
index c63ee7bc3331..93897c3f32e9 100644
--- a/drivers/media/common/videobuf2/videobuf2-v4l2.c
+++ b/drivers/media/common/videobuf2/videobuf2-v4l2.c
@@ -1278,12 +1278,20 @@  EXPORT_SYMBOL_GPL(vb2_ops_wait_finish);
 int vb2_request_validate(struct media_request *req)
 {
 	struct media_request_object *obj;
+	struct vb2_queue *q = NULL;
+	bool buffers_only = true;
 	int ret = 0;
 
-	if (!vb2_request_buffer_cnt(req))
-		return -ENOENT;
-
 	list_for_each_entry(obj, &req->objects, list) {
+		if (!vb2_request_object_is_buffer(obj)) {
+			buffers_only = false;
+		} else if (!q) {
+			struct vb2_buffer *vb;
+
+			vb = container_of(obj, struct vb2_buffer, req_obj);
+			q = vb->vb2_queue;
+		}
+
 		if (!obj->ops->prepare)
 			continue;
 
@@ -1292,6 +1300,11 @@  int vb2_request_validate(struct media_request *req)
 			break;
 	}
 
+	if (!q)
+		ret = -ENOENT;
+	else if (q->supports_ro_requests && !buffers_only)
+		ret = -EINVAL;
+
 	if (ret) {
 		list_for_each_entry_continue_reverse(obj, &req->objects, list)
 			if (obj->ops->unprepare)