[PATCH v7 21/49] media: dvb: Stop direct calls to queue num_buffers field

Hans Verkuil hverkuil-cisco at xs4all.nl
Tue Sep 19 06:40:56 PDT 2023


On 14/09/2023 15:32, Benjamin Gaignard wrote:
> Use vb2_get_num_buffers() to avoid using queue num_buffer field directly.
> 
> Signed-off-by: Benjamin Gaignard <benjamin.gaignard at collabora.com>
> ---
>  drivers/media/dvb-core/dvb_vb2.c          | 1 -
>  drivers/media/dvb-frontends/rtl2832_sdr.c | 5 +++--
>  2 files changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/media/dvb-core/dvb_vb2.c b/drivers/media/dvb-core/dvb_vb2.c
> index 3a966fdf814c..a731b755a0b9 100644
> --- a/drivers/media/dvb-core/dvb_vb2.c
> +++ b/drivers/media/dvb-core/dvb_vb2.c
> @@ -177,7 +177,6 @@ int dvb_vb2_init(struct dvb_vb2_ctx *ctx, const char *name, int nonblocking)
>  	q->ops = &dvb_vb2_qops;
>  	q->mem_ops = &vb2_vmalloc_memops;
>  	q->buf_ops = &dvb_vb2_buf_ops;
> -	q->num_buffers = 0;
>  	ret = vb2_core_queue_init(q);
>  	if (ret) {
>  		ctx->state = DVB_VB2_STATE_NONE;

This touches the dvb-core, and should be in a separate patch.

> diff --git a/drivers/media/dvb-frontends/rtl2832_sdr.c b/drivers/media/dvb-frontends/rtl2832_sdr.c
> index 02c619e51641..023db6e793f8 100644
> --- a/drivers/media/dvb-frontends/rtl2832_sdr.c
> +++ b/drivers/media/dvb-frontends/rtl2832_sdr.c
> @@ -439,12 +439,13 @@ static int rtl2832_sdr_queue_setup(struct vb2_queue *vq,
>  {
>  	struct rtl2832_sdr_dev *dev = vb2_get_drv_priv(vq);
>  	struct platform_device *pdev = dev->pdev;
> +	unsigned int q_num_bufs = vb2_get_num_buffers(vq);
>  
>  	dev_dbg(&pdev->dev, "nbuffers=%d\n", *nbuffers);
>  
>  	/* Need at least 8 buffers */
> -	if (vq->num_buffers + *nbuffers < 8)
> -		*nbuffers = 8 - vq->num_buffers;
> +	if (q_num_bufs + *nbuffers < 8)
> +		*nbuffers = 8 - q_num_bufs;
>  	*nplanes = 1;
>  	sizes[0] = PAGE_ALIGN(dev->buffersize);
>  	dev_dbg(&pdev->dev, "nbuffers=%d sizes[0]=%d\n", *nbuffers, sizes[0]);

This is really a generic issue with most of these patches:

queue_setup checks for a minimum number of buffers, but that should instead
be configured through the q->min_buffers_needed field.

A lot of older drivers were written before that field was added.

This is a good opportunity to just drop this check from queue_setup
and instead just set q->min_buffers_needed to 8.

Regards,

	Hans



More information about the Linux-rockchip mailing list