Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

media: videobuf2-v4l2: add vb2_request_queue/validate helpers

The generic vb2_request_validate helper function checks if
there are buffers in the request and if so, prepares (validates)
all objects in the request.

The generic vb2_request_queue helper function queues all buffer
objects in the validated request.

Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Reviewed-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>

authored by

Hans Verkuil and committed by
Mauro Carvalho Chehab
86f6bd3c c07aa48e

+55
+51
drivers/media/common/videobuf2/videobuf2-v4l2.c
··· 1100 1100 } 1101 1101 EXPORT_SYMBOL_GPL(vb2_ops_wait_finish); 1102 1102 1103 + /* 1104 + * Note that this function is called during validation time and 1105 + * thus the req_queue_mutex is held to ensure no request objects 1106 + * can be added or deleted while validating. So there is no need 1107 + * to protect the objects list. 1108 + */ 1109 + int vb2_request_validate(struct media_request *req) 1110 + { 1111 + struct media_request_object *obj; 1112 + int ret = 0; 1113 + 1114 + if (!vb2_request_has_buffers(req)) 1115 + return -ENOENT; 1116 + 1117 + list_for_each_entry(obj, &req->objects, list) { 1118 + if (!obj->ops->prepare) 1119 + continue; 1120 + 1121 + ret = obj->ops->prepare(obj); 1122 + if (ret) 1123 + break; 1124 + } 1125 + 1126 + if (ret) { 1127 + list_for_each_entry_continue_reverse(obj, &req->objects, list) 1128 + if (obj->ops->unprepare) 1129 + obj->ops->unprepare(obj); 1130 + return ret; 1131 + } 1132 + return 0; 1133 + } 1134 + EXPORT_SYMBOL_GPL(vb2_request_validate); 1135 + 1136 + void vb2_request_queue(struct media_request *req) 1137 + { 1138 + struct media_request_object *obj, *obj_safe; 1139 + 1140 + /* 1141 + * Queue all objects. Note that buffer objects are at the end of the 1142 + * objects list, after all other object types. Once buffer objects 1143 + * are queued, the driver might delete them immediately (if the driver 1144 + * processes the buffer at once), so we have to use 1145 + * list_for_each_entry_safe() to handle the case where the object we 1146 + * queue is deleted. 1147 + */ 1148 + list_for_each_entry_safe(obj, obj_safe, &req->objects, list) 1149 + if (obj->ops->queue) 1150 + obj->ops->queue(obj); 1151 + } 1152 + EXPORT_SYMBOL_GPL(vb2_request_queue); 1153 + 1103 1154 MODULE_DESCRIPTION("Driver helper framework for Video for Linux 2"); 1104 1155 MODULE_AUTHOR("Pawel Osciak <pawel@osciak.com>, Marek Szyprowski"); 1105 1156 MODULE_LICENSE("GPL");
+4
include/media/videobuf2-v4l2.h
··· 303 303 */ 304 304 void vb2_ops_wait_finish(struct vb2_queue *vq); 305 305 306 + struct media_request; 307 + int vb2_request_validate(struct media_request *req); 308 + void vb2_request_queue(struct media_request *req); 309 + 306 310 #endif /* _MEDIA_VIDEOBUF2_V4L2_H */