On Wed, Nov 8, 2023 at 7:24 PM Benjamin Gaignard <benjamin.gaignard@xxxxxxxxxxxxx> wrote: > > > Le 08/11/2023 à 09:50, Tomasz Figa a écrit : > > On Tue, Oct 31, 2023 at 05:30:13PM +0100, Benjamin Gaignard wrote: > >> This patch adds 2 helpers functions to add and remove vb2 buffers > >> from a queue. With these 2 and vb2_get_buffer(), bufs field of > >> struct vb2_queue becomes like a private member of the structure. > >> > >> After each call to vb2_get_buffer() we need to be sure that we get > >> a valid pointer in preparation for when buffers can be deleted. > >> > >> Signed-off-by: Benjamin Gaignard <benjamin.gaignard@xxxxxxxxxxxxx> > >> --- > >> .../media/common/videobuf2/videobuf2-core.c | 151 +++++++++++++----- > >> .../media/common/videobuf2/videobuf2-v4l2.c | 50 ++++-- > >> 2 files changed, 149 insertions(+), 52 deletions(-) > >> > >> diff --git a/drivers/media/common/videobuf2/videobuf2-core.c b/drivers/media/common/videobuf2/videobuf2-core.c > >> index 968b7c0e7934..b406a30a9b35 100644 > >> --- a/drivers/media/common/videobuf2/videobuf2-core.c > >> +++ b/drivers/media/common/videobuf2/videobuf2-core.c > >> @@ -408,6 +408,31 @@ static void init_buffer_cache_hints(struct vb2_queue *q, struct vb2_buffer *vb) > >> vb->skip_cache_sync_on_finish = 1; > >> } > >> > >> +/** > >> + * vb2_queue_add_buffer() - add a buffer to a queue > >> + * @q: pointer to &struct vb2_queue with videobuf2 queue. > >> + * @vb: pointer to &struct vb2_buffer to be added to the queue. > >> + * @index: index where add vb2_buffer in the queue > >> + */ > >> +static void vb2_queue_add_buffer(struct vb2_queue *q, struct vb2_buffer *vb, unsigned int index) > >> +{ > >> + WARN_ON(index >= VB2_MAX_FRAME || q->bufs[index]); > > nit: Would it make sense to also ensure that vb->vb2_queue is NULL? > > Since vb->vb2_queue and q->bufs[index] are always set and clear in the same > functions I don't think it is useful to test the both here. > Well, they are if the caller is not buggy. But I suppose the check is to detect buggy callers? For example, an m2m driver could accidentally call this on a buffer that was already added to another queue. Best regards, Tomasz