On 04/12/2018 10:29 AM, Tomasz Figa wrote: > On Mon, Apr 9, 2018 at 11:20 PM Hans Verkuil <hverkuil@xxxxxxxxx> wrote: > >> From: Hans Verkuil <hans.verkuil@xxxxxxxxx> > >> Generic helper function that checks if there are buffers in >> the request and if so, prepares and queues all objects in the >> request. > >> Signed-off-by: Hans Verkuil <hans.verkuil@xxxxxxxxx> >> --- >> drivers/media/common/videobuf2/videobuf2-v4l2.c | 39 > +++++++++++++++++++++++++ >> include/media/videobuf2-v4l2.h | 3 ++ >> 2 files changed, 42 insertions(+) > >> diff --git a/drivers/media/common/videobuf2/videobuf2-v4l2.c > b/drivers/media/common/videobuf2/videobuf2-v4l2.c >> index 73c1fd4da58a..3d0c74bb4220 100644 >> --- a/drivers/media/common/videobuf2/videobuf2-v4l2.c >> +++ b/drivers/media/common/videobuf2/videobuf2-v4l2.c >> @@ -1061,6 +1061,45 @@ void vb2_ops_wait_finish(struct vb2_queue *vq) >> } >> EXPORT_SYMBOL_GPL(vb2_ops_wait_finish); > >> +int vb2_request_queue(struct media_request *req) >> +{ >> + struct media_request_object *obj; >> + struct media_request_object *failed_obj = NULL; >> + int ret = 0; >> + >> + if (!vb2_core_request_has_buffers(req)) >> + return -ENOENT; >> + >> + list_for_each_entry(obj, &req->objects, list) { >> + if (!obj->ops->prepare) >> + continue; >> + >> + ret = obj->ops->prepare(obj); >> + >> + if (ret) { >> + failed_obj = obj; >> + break; >> + } >> + } >> + >> + if (ret) { >> + list_for_each_entry(obj, &req->objects, list) { >> + if (obj == failed_obj) >> + break; > > nit: If we use list_for_each_entry_continue_reverse() here, we wouldn't > need failed_obj. True. Done. Hans > > Best regards, > Tomasz >