Add the vb2_request_buffer_first() helper function to obtain the first vb2 buffer in the request. Signed-off-by: Hans Verkuil <hverkuil-cisco@xxxxxxxxx> --- .../media/common/videobuf2/videobuf2-core.c | 19 +++++++++++++++++++ include/media/videobuf2-core.h | 7 +++++++ 2 files changed, 26 insertions(+) diff --git a/drivers/media/common/videobuf2/videobuf2-core.c b/drivers/media/common/videobuf2/videobuf2-core.c index 10c552638878..3157fefe6500 100644 --- a/drivers/media/common/videobuf2/videobuf2-core.c +++ b/drivers/media/common/videobuf2/videobuf2-core.c @@ -1477,6 +1477,25 @@ unsigned int vb2_request_buffer_cnt(struct media_request *req) } EXPORT_SYMBOL_GPL(vb2_request_buffer_cnt); +struct vb2_buffer *vb2_request_buffer_first(struct media_request *req) +{ + struct media_request_object *obj; + struct vb2_buffer *vb = NULL; + unsigned long flags; + + spin_lock_irqsave(&req->lock, flags); + list_for_each_entry(obj, &req->objects, list) { + if (vb2_request_object_is_buffer(obj)) { + vb = container_of(obj, struct vb2_buffer, req_obj); + break; + } + } + spin_unlock_irqrestore(&req->lock, flags); + + return vb; +} +EXPORT_SYMBOL_GPL(vb2_request_buffer_first); + int vb2_core_prepare_buf(struct vb2_queue *q, unsigned int index, void *pb) { struct vb2_buffer *vb; diff --git a/include/media/videobuf2-core.h b/include/media/videobuf2-core.h index 0760f967365a..f508ce6b3152 100644 --- a/include/media/videobuf2-core.h +++ b/include/media/videobuf2-core.h @@ -1258,4 +1258,11 @@ bool vb2_request_object_is_buffer(struct media_request_object *obj); */ unsigned int vb2_request_buffer_cnt(struct media_request *req); +/** + * vb2_request_buffer_first() - return the first buffer in the request + * + * @req: the request. + */ +struct vb2_buffer *vb2_request_buffer_first(struct media_request *req); + #endif /* _MEDIA_VIDEOBUF2_CORE_H */ -- 2.30.2