Linux Media Controller development
 help / color / mirror / Atom feed
From: Stefan Klug <stefan.klug@ideasonboard.com>
To: Laurent Pinchart <laurent.pinchart@ideasonboard.com>,
	linux-media@vger.kernel.org
Cc: Nicolas Dufresne <nicolas.dufresne@collabora.com>
Subject: Re: [PATCH 01/25] media: v4l2-mem2mem: Document that v4l2_m2m_get_vq() never returns NULL
Date: Fri, 10 Oct 2025 10:35:55 +0200	[thread overview]
Message-ID: <176008535515.3214037.12070041639750618553@localhost> (raw)
In-Reply-To: <20251008175052.19925-2-laurent.pinchart@ideasonboard.com>

Hi Laurent,

Thank you for the patch.

Quoting Laurent Pinchart (2025-10-08 19:50:28)
> The v4l2_m2m_get_vq() never returns a NULL pointer, as the internal
> get_queue_ctx() helper always returns a non-NULL pointer. Many drivers
> check the return value against NULL, due to a combination of old code
> and cargo-cult programming. Even v4l2-mem2mem.c contains unneeded NULL
> checks.
> 
> Clarify the API by documenting explicitly that a NULL check is not
> needed, and simplify the code by removing the unneeded NULL checks from
> v4l2-mem2mem.c.
> 
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

Looks good to me.

Reviewed-by: Stefan Klug <stefan.klug@ideasonboard.com>

Best regards,
Stefan

> ---
>  drivers/media/v4l2-core/v4l2-mem2mem.c | 12 +-----------
>  include/media/v4l2-mem2mem.h           |  3 +++
>  2 files changed, 4 insertions(+), 11 deletions(-)
> 
> diff --git a/drivers/media/v4l2-core/v4l2-mem2mem.c b/drivers/media/v4l2-core/v4l2-mem2mem.c
> index eb22d6172462..b5e241629dfb 100644
> --- a/drivers/media/v4l2-core/v4l2-mem2mem.c
> +++ b/drivers/media/v4l2-core/v4l2-mem2mem.c
> @@ -123,13 +123,7 @@ static struct v4l2_m2m_queue_ctx *get_queue_ctx(struct v4l2_m2m_ctx *m2m_ctx,
>  struct vb2_queue *v4l2_m2m_get_vq(struct v4l2_m2m_ctx *m2m_ctx,
>                                        enum v4l2_buf_type type)
>  {
> -       struct v4l2_m2m_queue_ctx *q_ctx;
> -
> -       q_ctx = get_queue_ctx(m2m_ctx, type);
> -       if (!q_ctx)
> -               return NULL;
> -
> -       return &q_ctx->q;
> +       return &get_queue_ctx(m2m_ctx, type)->q;
>  }
>  EXPORT_SYMBOL(v4l2_m2m_get_vq);
>  
> @@ -1289,8 +1283,6 @@ void v4l2_m2m_buf_queue(struct v4l2_m2m_ctx *m2m_ctx,
>         unsigned long flags;
>  
>         q_ctx = get_queue_ctx(m2m_ctx, vbuf->vb2_buf.vb2_queue->type);
> -       if (!q_ctx)
> -               return;
>  
>         spin_lock_irqsave(&q_ctx->rdy_spinlock, flags);
>         list_add_tail(&b->list, &q_ctx->rdy_queue);
> @@ -1392,8 +1384,6 @@ int v4l2_m2m_ioctl_remove_bufs(struct file *file, void *priv,
>         struct v4l2_fh *fh = file->private_data;
>         struct vb2_queue *q = v4l2_m2m_get_vq(fh->m2m_ctx, remove->type);
>  
> -       if (!q)
> -               return -EINVAL;
>         if (q->type != remove->type)
>                 return -EINVAL;
>  
> diff --git a/include/media/v4l2-mem2mem.h b/include/media/v4l2-mem2mem.h
> index 2e55a13ed3bb..670e8ec60450 100644
> --- a/include/media/v4l2-mem2mem.h
> +++ b/include/media/v4l2-mem2mem.h
> @@ -153,6 +153,9 @@ void *v4l2_m2m_get_curr_priv(struct v4l2_m2m_dev *m2m_dev);
>   *
>   * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx
>   * @type: type of the V4L2 buffer, as defined by enum &v4l2_buf_type
> + *
> + * This function returns the capture queue when @type is a capture type, and the
> + * output queue otherwise. It never returns a NULL pointer.
>   */
>  struct vb2_queue *v4l2_m2m_get_vq(struct v4l2_m2m_ctx *m2m_ctx,
>                                        enum v4l2_buf_type type);
> -- 
> Regards,
> 
> Laurent Pinchart
> 
>

  reply	other threads:[~2025-10-10  8:35 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-08 17:50 [PATCH 00/25] media: v4l2-mem2mem: Reduce cargo-cult Laurent Pinchart
2025-10-08 17:50 ` [PATCH 01/25] media: v4l2-mem2mem: Document that v4l2_m2m_get_vq() never returns NULL Laurent Pinchart
2025-10-10  8:35   ` Stefan Klug [this message]
2025-10-08 17:50 ` [PATCH 02/25] media: allgro-dvt: Drop unneeded v4l2_m2m_get_vq() NULL check Laurent Pinchart
2025-10-08 17:50 ` [PATCH 03/25] media: meson-g2d: " Laurent Pinchart
2025-10-08 18:13   ` Neil Armstrong
2025-10-08 17:50 ` [PATCH 04/25] media: amphion: " Laurent Pinchart
2025-10-08 17:50 ` [PATCH 05/25] media: coda: " Laurent Pinchart
2025-10-09  8:11   ` Philipp Zabel
2025-10-08 17:50 ` [PATCH 06/25] media: imagination: e5010: " Laurent Pinchart
2025-10-08 17:50 ` [PATCH 07/25] media: m2m-deinterlace: " Laurent Pinchart
2025-10-08 17:50 ` [PATCH 08/25] media: mediatek: jpeg: " Laurent Pinchart
2025-10-08 17:50 ` [PATCH 09/25] media: mediatek: vcodec: " Laurent Pinchart
2025-10-08 17:50 ` [PATCH 10/25] media: dw100: " Laurent Pinchart
2025-10-10  8:40   ` Stefan Klug
2025-10-08 17:50 ` [PATCH 11/25] media: imx-jpeg: " Laurent Pinchart
2025-10-08 20:01   ` Frank Li
2025-10-08 17:50 ` [PATCH 12/25] media: imx-pxp: " Laurent Pinchart
2025-10-08 20:02   ` Frank Li
2025-10-09  8:11   ` Philipp Zabel
2025-10-08 17:50 ` [PATCH 13/25] media: nxp: imx8-isi: " Laurent Pinchart
2025-10-08 20:02   ` Frank Li
2025-10-08 17:50 ` [PATCH 14/25] media: mx2_emmaprp: " Laurent Pinchart
2025-10-08 17:50 ` [PATCH 15/25] media: qcom: iris: " Laurent Pinchart
2025-10-08 23:51   ` Bryan O'Donoghue
2025-10-09 13:53   ` Dikshita Agarwal
2025-10-10 11:14     ` Laurent Pinchart
2025-10-08 17:50 ` [PATCH 16/25] media: qcom: venus: " Laurent Pinchart
2025-10-08 23:52   ` Bryan O'Donoghue
2025-10-09  7:42   ` Dikshita Agarwal
2025-10-08 17:50 ` [PATCH 17/25] media: renesas: fdp1: " Laurent Pinchart
2025-10-08 17:50 ` [PATCH 18/25] media: rcar_jpu: " Laurent Pinchart
2025-10-08 17:50 ` [PATCH 19/25] media: platform: rga: " Laurent Pinchart
2025-10-08 17:50 ` [PATCH 20/25] media: samsung: s5p-g2d: " Laurent Pinchart
2025-10-10 11:00   ` Lukasz Stelmach
2025-10-08 17:50 ` [PATCH 21/25] media: samsung: s5p-jpeg: " Laurent Pinchart
2025-10-08 17:50 ` [PATCH 22/25] media: stm32: dma2d: " Laurent Pinchart
2025-10-08 17:50 ` [PATCH 23/25] media: ti: vpe: " Laurent Pinchart
2025-10-08 17:50 ` [PATCH 24/25] media: vicodec: " Laurent Pinchart
2025-10-08 17:50 ` [PATCH 25/25] media: vim2m: " Laurent Pinchart
2025-10-08 18:24 ` [PATCH 00/25] media: v4l2-mem2mem: Reduce cargo-cult Nicolas Dufresne
2025-10-08 19:21   ` Laurent Pinchart

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=176008535515.3214037.12070041639750618553@localhost \
    --to=stefan.klug@ideasonboard.com \
    --cc=laurent.pinchart@ideasonboard.com \
    --cc=linux-media@vger.kernel.org \
    --cc=nicolas.dufresne@collabora.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox