[PATCH v14 05/56] media: videobuf2: Access vb2_queue bufs array through helper functions

Benjamin Gaignard benjamin.gaignard at collabora.com
Wed Nov 8 02:24:20 PST 2023


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 at collabora.com>
>> ---
>>   .../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.

>
>> +
>> +	q->bufs[index] = vb;
>> +	vb->index = index;
>> +	vb->vb2_queue = q;
>> +}
> [snip]
>> diff --git a/drivers/media/common/videobuf2/videobuf2-v4l2.c b/drivers/media/common/videobuf2/videobuf2-v4l2.c
>> index d19d82a75ac6..2ffb097bf00a 100644
>> --- a/drivers/media/common/videobuf2/videobuf2-v4l2.c
>> +++ b/drivers/media/common/videobuf2/videobuf2-v4l2.c
>> @@ -377,6 +377,12 @@ static int vb2_queue_or_prepare_buf(struct vb2_queue *q, struct media_device *md
>>   		return -EINVAL;
>>   	}
>>   
>> +	vb = vb2_get_buffer(q, b->index);
>> +	if (!vb) {
>> +		dprintk(q, 1, "%s: buffer %u is NULL\n", opname,  b->index);
>> +		return -EINVAL;
>> +	}
>> +
> Is this a leftover from earlier revisions? I think it shouldn't be
> needed anymore after the previous patch which changed the function to
> get vb as an argument.

You are right I will fix it.

>
> Best regards,
> Tomasz
> _______________________________________________
> Kernel mailing list -- kernel at mailman.collabora.com
> To unsubscribe send an email to kernel-leave at mailman.collabora.com



More information about the Linux-rockchip mailing list