Linux Media Controller development
 help / color / mirror / Atom feed
* [PATCH 00/25] media: v4l2-mem2mem: Reduce cargo-cult
@ 2025-10-08 17:50 Laurent Pinchart
  2025-10-08 17:50 ` [PATCH 01/25] media: v4l2-mem2mem: Document that v4l2_m2m_get_vq() never returns NULL Laurent Pinchart
                   ` (25 more replies)
  0 siblings, 26 replies; 42+ messages in thread
From: Laurent Pinchart @ 2025-10-08 17:50 UTC (permalink / raw)
  To: linux-media, linux-mediatek, imx, linux-amlogic,
	linux-renesas-soc, linux-stm32, linux-rockchip, linux-arm-kernel,
	linux-arm-msm
  Cc: Nicolas Dufresne, Matthew Majewski, Mirela Rabulea,
	Jacek Anaszewski, Michael Tretter, Devarsh Thakkar,
	Uwe Kleine-König, AngeloGioacchino Del Regno,
	Martin Blumenstingl, Alexandre Torgue, Philipp Zabel,
	Arnd Bergmann, Sylwester Nawrocki, Ming Qian,
	Pengutronix Kernel Team, Kieran Bingham, Nathan Chancellor,
	Sascha Hauer, Hans Verkuil, Mikhail Ulyanov, Kevin Hilman,
	Xavier Roumegue, Shuah Khan, Andrzej Pietrasiewicz, Tiffany Lin,
	Zhou Peng, Dikshita Agarwal, Vikash Garodia, Yunfei Dong,
	Ezequiel Garcia, Neil Armstrong, Jiasheng Jiang, Shawn Guo,
	Łukasz Stelmach, Abhinav Kumar, Heiko Stuebner,
	Benoit Parrot, Andrew-CT Chen, Geert Uytterhoeven, Magnus Damm,
	Sebastian Fricke, Maxime Coquelin, Jacob Chen, Bin Liu,
	Matthias Brugger, Fabio Estevam, Jerome Brunet,
	Bryan O'Donoghue

Hello,

The v4l2_m2m_get_vq() function never returns NULL, but many mem2mem
drivers still check its return value and consider NULL as an error. This
may have originated a long time ago from valid checks when
v4l2_m2m_get_vq() could return NULL, with drivers then just copying the
checks. This series attempts to stop the cargo-cult behaviour.

Patch 01/25 starts by explicitly stating in kerneldoc that the
v4l2_m2m_get_vq() function never returns NULL. All the other patches
drop NULL checks from drivers.

I have carefully checked all patched locations in all drivers. They fall
in 3 categories:

- Checks in the VIDIOC_G_FMT, VIDIOC_TRY_FMT and VIDIOC_S_FMT handlers:
  Those may have been added to ensure that the format type has a valid
  value, but that is ensured by the V4L2 ioctl core before calling the
  handlers. The checks can be dropped without a need to replace them
  with proper type checks.

- Checks in the VIDIOC_S_SELECTION handler: The only location where this
  is performed has an explicit type check, so the NULL check can also be
  dropped.

- Checks in other locations where the type parameter to the
  v4l2_m2m_get_vq() function is hardcoded: The hardcoded type is valid,
  so the NULL check can't have been meant to check the type. It can also
  be removed.

There's no dependency between any of those patches so they can be merged
in any order.

Laurent Pinchart (25):
  media: v4l2-mem2mem: Document that v4l2_m2m_get_vq() never returns
    NULL
  media: allgro-dvt: Drop unneeded v4l2_m2m_get_vq() NULL check
  media: meson-g2d: Drop unneeded v4l2_m2m_get_vq() NULL check
  media: amphion: Drop unneeded v4l2_m2m_get_vq() NULL check
  media: coda: Drop unneeded v4l2_m2m_get_vq() NULL check
  media: imagination: e5010: Drop unneeded v4l2_m2m_get_vq() NULL check
  media: m2m-deinterlace: Drop unneeded v4l2_m2m_get_vq() NULL check
  media: mediatek: jpeg: Drop unneeded v4l2_m2m_get_vq() NULL check
  media: mediatek: vcodec: Drop unneeded v4l2_m2m_get_vq() NULL check
  media: dw100: Drop unneeded v4l2_m2m_get_vq() NULL check
  media: imx-jpeg: Drop unneeded v4l2_m2m_get_vq() NULL check
  media: imx-pxp: Drop unneeded v4l2_m2m_get_vq() NULL check
  media: nxp: imx8-isi: Drop unneeded v4l2_m2m_get_vq() NULL check
  media: mx2_emmaprp: Drop unneeded v4l2_m2m_get_vq() NULL check
  media: qcom: iris: Drop unneeded v4l2_m2m_get_vq() NULL check
  media: qcom: venus: Drop unneeded v4l2_m2m_get_vq() NULL check
  media: renesas: fdp1: Drop unneeded v4l2_m2m_get_vq() NULL check
  media: rcar_jpu: Drop unneeded v4l2_m2m_get_vq() NULL check
  media: platform: rga: Drop unneeded v4l2_m2m_get_vq() NULL check
  media: samsung: s5p-g2d: Drop unneeded v4l2_m2m_get_vq() NULL check
  media: samsung: s5p-jpeg: Drop unneeded v4l2_m2m_get_vq() NULL check
  media: stm32: dma2d: Drop unneeded v4l2_m2m_get_vq() NULL check
  media: ti: vpe: Drop unneeded v4l2_m2m_get_vq() NULL check
  media: vicodec: Drop unneeded v4l2_m2m_get_vq() NULL check
  media: vim2m: Drop unneeded v4l2_m2m_get_vq() NULL check

 drivers/media/platform/allegro-dvt/allegro-core.c    |  2 --
 drivers/media/platform/amlogic/meson-ge2d/ge2d.c     |  5 -----
 drivers/media/platform/amphion/vdec.c                |  2 --
 drivers/media/platform/amphion/venc.c                |  2 --
 .../media/platform/chips-media/coda/coda-common.c    |  4 ----
 drivers/media/platform/imagination/e5010-jpeg-enc.c  |  4 ----
 drivers/media/platform/m2m-deinterlace.c             |  7 -------
 drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c |  7 -------
 .../mediatek/vcodec/decoder/mtk_vcodec_dec.c         |  7 -------
 .../vcodec/decoder/vdec/vdec_av1_req_lat_if.c        |  2 --
 .../vcodec/decoder/vdec/vdec_vp9_req_lat_if.c        |  2 --
 .../mediatek/vcodec/encoder/mtk_vcodec_enc.c         |  8 --------
 drivers/media/platform/nxp/dw100/dw100.c             |  7 -------
 drivers/media/platform/nxp/imx-jpeg/mxc-jpeg.c       |  4 ----
 drivers/media/platform/nxp/imx-pxp.c                 |  7 -------
 drivers/media/platform/nxp/imx8-isi/imx8-isi-m2m.c   |  2 --
 drivers/media/platform/nxp/mx2_emmaprp.c             |  7 -------
 drivers/media/platform/qcom/iris/iris_vdec.c         |  2 --
 drivers/media/platform/qcom/venus/vdec.c             |  2 --
 drivers/media/platform/qcom/venus/venc.c             |  2 --
 drivers/media/platform/renesas/rcar_fdp1.c           |  3 ---
 drivers/media/platform/renesas/rcar_jpu.c            |  8 --------
 drivers/media/platform/rockchip/rga/rga.c            |  4 ----
 drivers/media/platform/samsung/s5p-g2d/g2d.c         |  4 ----
 drivers/media/platform/samsung/s5p-jpeg/jpeg-core.c  |  7 -------
 drivers/media/platform/st/stm32/dma2d/dma2d.c        |  5 -----
 drivers/media/platform/ti/vpe/vpe.c                  |  7 -------
 drivers/media/test-drivers/vicodec/vicodec-core.c    |  7 -------
 drivers/media/test-drivers/vim2m.c                   | 12 ------------
 drivers/media/v4l2-core/v4l2-mem2mem.c               | 12 +-----------
 include/media/v4l2-mem2mem.h                         |  3 +++
 31 files changed, 4 insertions(+), 153 deletions(-)


base-commit: e5f0a698b34ed76002dc5cff3804a61c80233a7a
-- 
Regards,

Laurent Pinchart


^ permalink raw reply	[flat|nested] 42+ messages in thread

* [PATCH 01/25] media: v4l2-mem2mem: Document that v4l2_m2m_get_vq() never returns NULL
  2025-10-08 17:50 [PATCH 00/25] media: v4l2-mem2mem: Reduce cargo-cult Laurent Pinchart
@ 2025-10-08 17:50 ` Laurent Pinchart
  2025-10-10  8:35   ` Stefan Klug
  2025-10-08 17:50 ` [PATCH 02/25] media: allgro-dvt: Drop unneeded v4l2_m2m_get_vq() NULL check Laurent Pinchart
                   ` (24 subsequent siblings)
  25 siblings, 1 reply; 42+ messages in thread
From: Laurent Pinchart @ 2025-10-08 17:50 UTC (permalink / raw)
  To: linux-media; +Cc: Nicolas Dufresne

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>
---
 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


^ permalink raw reply related	[flat|nested] 42+ messages in thread

* [PATCH 02/25] media: allgro-dvt: Drop unneeded v4l2_m2m_get_vq() NULL check
  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-08 17:50 ` Laurent Pinchart
  2025-10-08 17:50 ` [PATCH 03/25] media: meson-g2d: " Laurent Pinchart
                   ` (23 subsequent siblings)
  25 siblings, 0 replies; 42+ messages in thread
From: Laurent Pinchart @ 2025-10-08 17:50 UTC (permalink / raw)
  To: linux-media; +Cc: Nicolas Dufresne, Michael Tretter, Pengutronix Kernel Team

The v4l2_m2m_get_vq() function never returns NULL. The check may have
been intended to catch invalid format types, but that's not needed as
the V4L2 core picks the appropriate VIDIOC_S_FMT ioctl handler based on
the format type, so the type can't be incorrect. Drop the unneeded
return value check.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 drivers/media/platform/allegro-dvt/allegro-core.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/media/platform/allegro-dvt/allegro-core.c b/drivers/media/platform/allegro-dvt/allegro-core.c
index eb03df0d8652..7dce4b9c1eb9 100644
--- a/drivers/media/platform/allegro-dvt/allegro-core.c
+++ b/drivers/media/platform/allegro-dvt/allegro-core.c
@@ -3331,8 +3331,6 @@ static int allegro_s_fmt_vid_cap(struct file *file, void *fh,
 		return err;
 
 	vq = v4l2_m2m_get_vq(channel->fh.m2m_ctx, f->type);
-	if (!vq)
-		return -EINVAL;
 	if (vb2_is_busy(vq))
 		return -EBUSY;
 
-- 
Regards,

Laurent Pinchart


^ permalink raw reply related	[flat|nested] 42+ messages in thread

* [PATCH 03/25] media: meson-g2d: Drop unneeded v4l2_m2m_get_vq() NULL check
  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-08 17:50 ` [PATCH 02/25] media: allgro-dvt: Drop unneeded v4l2_m2m_get_vq() NULL check Laurent Pinchart
@ 2025-10-08 17:50 ` Laurent Pinchart
  2025-10-08 18:13   ` Neil Armstrong
  2025-10-08 17:50 ` [PATCH 04/25] media: amphion: " Laurent Pinchart
                   ` (22 subsequent siblings)
  25 siblings, 1 reply; 42+ messages in thread
From: Laurent Pinchart @ 2025-10-08 17:50 UTC (permalink / raw)
  To: linux-media, linux-amlogic, linux-arm-kernel
  Cc: Nicolas Dufresne, Neil Armstrong, Kevin Hilman, Jerome Brunet,
	Martin Blumenstingl

The v4l2_m2m_get_vq() function never returns NULL. The check was
probably intended to catch invalid format types, but that's not needed
as the V4L2 core picks the appropriate VIDIOC_G_FMT ioctl handler based
on the format type, so the type can't be incorrect. Drop the unneeded
return value check and, as the return value is not used for other
purposes and the function has no side effect, the function call as well.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 drivers/media/platform/amlogic/meson-ge2d/ge2d.c | 5 -----
 1 file changed, 5 deletions(-)

diff --git a/drivers/media/platform/amlogic/meson-ge2d/ge2d.c b/drivers/media/platform/amlogic/meson-ge2d/ge2d.c
index 0c004bb8ba05..a9323b383547 100644
--- a/drivers/media/platform/amlogic/meson-ge2d/ge2d.c
+++ b/drivers/media/platform/amlogic/meson-ge2d/ge2d.c
@@ -627,13 +627,8 @@ static int vidioc_s_fmt_cap(struct file *file, void *priv, struct v4l2_format *f
 static int vidioc_g_fmt(struct file *file, void *priv, struct v4l2_format *f)
 {
 	struct ge2d_ctx *ctx = priv;
-	struct vb2_queue *vq;
 	struct ge2d_frame *frm;
 
-	vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, f->type);
-	if (!vq)
-		return -EINVAL;
-
 	frm = get_frame(ctx, f->type);
 
 	f->fmt.pix = frm->pix_fmt;
-- 
Regards,

Laurent Pinchart


^ permalink raw reply related	[flat|nested] 42+ messages in thread

* [PATCH 04/25] media: amphion: Drop unneeded v4l2_m2m_get_vq() NULL check
  2025-10-08 17:50 [PATCH 00/25] media: v4l2-mem2mem: Reduce cargo-cult Laurent Pinchart
                   ` (2 preceding siblings ...)
  2025-10-08 17:50 ` [PATCH 03/25] media: meson-g2d: " Laurent Pinchart
@ 2025-10-08 17:50 ` Laurent Pinchart
  2025-10-08 17:50 ` [PATCH 05/25] media: coda: " Laurent Pinchart
                   ` (21 subsequent siblings)
  25 siblings, 0 replies; 42+ messages in thread
From: Laurent Pinchart @ 2025-10-08 17:50 UTC (permalink / raw)
  To: linux-media; +Cc: Nicolas Dufresne, Ming Qian, Zhou Peng

The v4l2_m2m_get_vq() function never returns NULL. The check may have
been intended to catch invalid format types, but that's not needed as
the V4L2 core picks the appropriate VIDIOC_S_FMT ioctl handler based on
the format type, so the type can't be incorrect. Drop the unneeded
return value check.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 drivers/media/platform/amphion/vdec.c | 2 --
 drivers/media/platform/amphion/venc.c | 2 --
 2 files changed, 4 deletions(-)

diff --git a/drivers/media/platform/amphion/vdec.c b/drivers/media/platform/amphion/vdec.c
index 32eef2fd1f2a..79790fbadc95 100644
--- a/drivers/media/platform/amphion/vdec.c
+++ b/drivers/media/platform/amphion/vdec.c
@@ -532,8 +532,6 @@ static int vdec_s_fmt_common(struct vpu_inst *inst, struct v4l2_format *f)
 		return -EINVAL;
 
 	q = v4l2_m2m_get_vq(inst->fh.m2m_ctx, f->type);
-	if (!q)
-		return -EINVAL;
 	if (vb2_is_busy(q))
 		return -EBUSY;
 
diff --git a/drivers/media/platform/amphion/venc.c b/drivers/media/platform/amphion/venc.c
index c5c1f1fbaa80..319fbae70571 100644
--- a/drivers/media/platform/amphion/venc.c
+++ b/drivers/media/platform/amphion/venc.c
@@ -223,8 +223,6 @@ static int venc_s_fmt(struct file *file, void *fh, struct v4l2_format *f)
 	struct v4l2_pix_format_mplane *pix_mp = &f->fmt.pix_mp;
 
 	q = v4l2_m2m_get_vq(inst->fh.m2m_ctx, f->type);
-	if (!q)
-		return -EINVAL;
 	if (vb2_is_busy(q))
 		return -EBUSY;
 
-- 
Regards,

Laurent Pinchart


^ permalink raw reply related	[flat|nested] 42+ messages in thread

* [PATCH 05/25] media: coda: Drop unneeded v4l2_m2m_get_vq() NULL check
  2025-10-08 17:50 [PATCH 00/25] media: v4l2-mem2mem: Reduce cargo-cult Laurent Pinchart
                   ` (3 preceding siblings ...)
  2025-10-08 17:50 ` [PATCH 04/25] media: amphion: " Laurent Pinchart
@ 2025-10-08 17:50 ` Laurent Pinchart
  2025-10-09  8:11   ` Philipp Zabel
  2025-10-08 17:50 ` [PATCH 06/25] media: imagination: e5010: " Laurent Pinchart
                   ` (20 subsequent siblings)
  25 siblings, 1 reply; 42+ messages in thread
From: Laurent Pinchart @ 2025-10-08 17:50 UTC (permalink / raw)
  To: linux-media; +Cc: Nicolas Dufresne, Philipp Zabel

The v4l2_m2m_get_vq() function never returns NULL. The check may have
been intended to catch invalid format types, but that's not needed as
the V4L2 core picks the appropriate VIDIOC_S_FMT ioctl handler based on
the format type, so the type can't be incorrect. Drop the unneeded
return value check.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 drivers/media/platform/chips-media/coda/coda-common.c | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/drivers/media/platform/chips-media/coda/coda-common.c b/drivers/media/platform/chips-media/coda/coda-common.c
index e6e3f5ec24f6..5451b01e0815 100644
--- a/drivers/media/platform/chips-media/coda/coda-common.c
+++ b/drivers/media/platform/chips-media/coda/coda-common.c
@@ -785,8 +785,6 @@ static int coda_s_fmt(struct coda_ctx *ctx, struct v4l2_format *f,
 	struct vb2_queue *vq;
 
 	vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, f->type);
-	if (!vq)
-		return -EINVAL;
 
 	q_data = get_q_data(ctx, f->type);
 	if (!q_data)
@@ -937,8 +935,6 @@ static int coda_s_fmt_vid_out(struct file *file, void *priv,
 	ctx->codec = codec;
 
 	dst_vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE);
-	if (!dst_vq)
-		return -EINVAL;
 
 	/*
 	 * Setting the capture queue format is not possible while the capture
-- 
Regards,

Laurent Pinchart


^ permalink raw reply related	[flat|nested] 42+ messages in thread

* [PATCH 06/25] media: imagination: e5010: Drop unneeded v4l2_m2m_get_vq() NULL check
  2025-10-08 17:50 [PATCH 00/25] media: v4l2-mem2mem: Reduce cargo-cult Laurent Pinchart
                   ` (4 preceding siblings ...)
  2025-10-08 17:50 ` [PATCH 05/25] media: coda: " Laurent Pinchart
@ 2025-10-08 17:50 ` Laurent Pinchart
  2025-10-08 17:50 ` [PATCH 07/25] media: m2m-deinterlace: " Laurent Pinchart
                   ` (19 subsequent siblings)
  25 siblings, 0 replies; 42+ messages in thread
From: Laurent Pinchart @ 2025-10-08 17:50 UTC (permalink / raw)
  To: linux-media; +Cc: Nicolas Dufresne, Devarsh Thakkar

The v4l2_m2m_get_vq() function never returns NULL.

In e5010_s_fmt(), the check may have been intended to catch invalid
format types, but that's not needed as the V4L2 core picks the
appropriate VIDIOC_S_FMT ioctl handler based on the format type, so the
type can't be incorrect.

In e5010_s_selection(), the function performs an explicit type check, so
the NULL check couldn't have been intended as a type check.

Drop the unneeded return value check.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 drivers/media/platform/imagination/e5010-jpeg-enc.c | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/drivers/media/platform/imagination/e5010-jpeg-enc.c b/drivers/media/platform/imagination/e5010-jpeg-enc.c
index ae868d9f73e1..a7afcc300b55 100644
--- a/drivers/media/platform/imagination/e5010-jpeg-enc.c
+++ b/drivers/media/platform/imagination/e5010-jpeg-enc.c
@@ -396,8 +396,6 @@ static int e5010_s_fmt(struct file *file, void *priv, struct v4l2_format *f)
 	struct e5010_fmt *fmt;
 
 	vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, f->type);
-	if (!vq)
-		return -EINVAL;
 
 	if (vb2_is_busy(vq)) {
 		v4l2_err(&ctx->e5010->v4l2_dev, "queue busy\n");
@@ -496,8 +494,6 @@ static int e5010_s_selection(struct file *file, void *fh, struct v4l2_selection
 	struct v4l2_rect base_rect;
 
 	vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, s->type);
-	if (!vq)
-		return -EINVAL;
 
 	if (vb2_is_streaming(vq))
 		return -EBUSY;
-- 
Regards,

Laurent Pinchart


^ permalink raw reply related	[flat|nested] 42+ messages in thread

* [PATCH 07/25] media: m2m-deinterlace: Drop unneeded v4l2_m2m_get_vq() NULL check
  2025-10-08 17:50 [PATCH 00/25] media: v4l2-mem2mem: Reduce cargo-cult Laurent Pinchart
                   ` (5 preceding siblings ...)
  2025-10-08 17:50 ` [PATCH 06/25] media: imagination: e5010: " Laurent Pinchart
@ 2025-10-08 17:50 ` Laurent Pinchart
  2025-10-08 17:50 ` [PATCH 08/25] media: mediatek: jpeg: " Laurent Pinchart
                   ` (18 subsequent siblings)
  25 siblings, 0 replies; 42+ messages in thread
From: Laurent Pinchart @ 2025-10-08 17:50 UTC (permalink / raw)
  To: linux-media
  Cc: Nicolas Dufresne, Hans Verkuil, Uwe Kleine-König,
	Andrzej Pietrasiewicz, Neil Armstrong

The v4l2_m2m_get_vq() function never returns NULL.

In the set format handler, the check may have been intended to catch
invalid format types, but that's not needed as the V4L2 core picks the
appropriate VIDIOC_S_FMT ioctl handler based on the format type, so the
type can't be incorrect.

In the get format handler, the return value is not used for any purpose
other than the NULL check, which was therefore probably intended to
catch invalid format types. That's not needed for the same reason as in
the set format handler.

Drop the unneeded return value checks and, as the function has no side
effect, the unneeded function call as well.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 drivers/media/platform/m2m-deinterlace.c | 7 -------
 1 file changed, 7 deletions(-)

diff --git a/drivers/media/platform/m2m-deinterlace.c b/drivers/media/platform/m2m-deinterlace.c
index 5188f3189096..009e866859f9 100644
--- a/drivers/media/platform/m2m-deinterlace.c
+++ b/drivers/media/platform/m2m-deinterlace.c
@@ -480,13 +480,8 @@ static int vidioc_enum_fmt_vid_out(struct file *file, void *priv,
 
 static int vidioc_g_fmt(struct deinterlace_ctx *ctx, struct v4l2_format *f)
 {
-	struct vb2_queue *vq;
 	struct deinterlace_q_data *q_data;
 
-	vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, f->type);
-	if (!vq)
-		return -EINVAL;
-
 	q_data = get_q_data(f->type);
 
 	f->fmt.pix.width	= q_data->width;
@@ -581,8 +576,6 @@ static int vidioc_s_fmt(struct deinterlace_ctx *ctx, struct v4l2_format *f)
 	struct vb2_queue *vq;
 
 	vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, f->type);
-	if (!vq)
-		return -EINVAL;
 
 	q_data = get_q_data(f->type);
 	if (!q_data)
-- 
Regards,

Laurent Pinchart


^ permalink raw reply related	[flat|nested] 42+ messages in thread

* [PATCH 08/25] media: mediatek: jpeg: Drop unneeded v4l2_m2m_get_vq() NULL check
  2025-10-08 17:50 [PATCH 00/25] media: v4l2-mem2mem: Reduce cargo-cult Laurent Pinchart
                   ` (6 preceding siblings ...)
  2025-10-08 17:50 ` [PATCH 07/25] media: m2m-deinterlace: " Laurent Pinchart
@ 2025-10-08 17:50 ` Laurent Pinchart
  2025-10-08 17:50 ` [PATCH 09/25] media: mediatek: vcodec: " Laurent Pinchart
                   ` (17 subsequent siblings)
  25 siblings, 0 replies; 42+ messages in thread
From: Laurent Pinchart @ 2025-10-08 17:50 UTC (permalink / raw)
  To: linux-media, linux-arm-kernel, linux-mediatek
  Cc: Nicolas Dufresne, Bin Liu, Matthias Brugger,
	AngeloGioacchino Del Regno

The v4l2_m2m_get_vq() function never returns NULL.

In the set format handler, the check may have been intended to catch
invalid format types, but that's not needed as the V4L2 core picks the
appropriate VIDIOC_S_FMT ioctl handler based on the format type, so the
type can't be incorrect.

In the get format handler, the return value is not used for any purpose
other than the NULL check, which was therefore probably intended to
catch invalid format types. That's not needed for the same reason as in
the set format handler.

Drop the unneeded return value checks and, as the function has no side
effect, the unneeded function call as well.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c | 7 -------
 1 file changed, 7 deletions(-)

diff --git a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c
index 7eb12449b63a..35c70ec3ad2c 100644
--- a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c
+++ b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c
@@ -302,17 +302,12 @@ static int mtk_jpeg_try_fmt_mplane(struct v4l2_pix_format_mplane *pix_mp,
 static int mtk_jpeg_g_fmt_vid_mplane(struct file *file, void *priv,
 				     struct v4l2_format *f)
 {
-	struct vb2_queue *vq;
 	struct mtk_jpeg_q_data *q_data = NULL;
 	struct v4l2_pix_format_mplane *pix_mp = &f->fmt.pix_mp;
 	struct mtk_jpeg_ctx *ctx = mtk_jpeg_fh_to_ctx(priv);
 	struct mtk_jpeg_dev *jpeg = ctx->jpeg;
 	int i;
 
-	vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, f->type);
-	if (!vq)
-		return -EINVAL;
-
 	q_data = mtk_jpeg_get_q_data(ctx, f->type);
 
 	pix_mp->width = q_data->pix_mp.width;
@@ -416,8 +411,6 @@ static int mtk_jpeg_s_fmt_mplane(struct mtk_jpeg_ctx *ctx,
 	int i;
 
 	vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, f->type);
-	if (!vq)
-		return -EINVAL;
 
 	q_data = mtk_jpeg_get_q_data(ctx, f->type);
 
-- 
Regards,

Laurent Pinchart


^ permalink raw reply related	[flat|nested] 42+ messages in thread

* [PATCH 09/25] media: mediatek: vcodec: Drop unneeded v4l2_m2m_get_vq() NULL check
  2025-10-08 17:50 [PATCH 00/25] media: v4l2-mem2mem: Reduce cargo-cult Laurent Pinchart
                   ` (7 preceding siblings ...)
  2025-10-08 17:50 ` [PATCH 08/25] media: mediatek: jpeg: " Laurent Pinchart
@ 2025-10-08 17:50 ` Laurent Pinchart
  2025-10-08 17:50 ` [PATCH 10/25] media: dw100: " Laurent Pinchart
                   ` (16 subsequent siblings)
  25 siblings, 0 replies; 42+ messages in thread
From: Laurent Pinchart @ 2025-10-08 17:50 UTC (permalink / raw)
  To: linux-media, linux-arm-kernel, linux-mediatek
  Cc: Nicolas Dufresne, Tiffany Lin, Andrew-CT Chen, Yunfei Dong,
	Matthias Brugger, AngeloGioacchino Del Regno, Arnd Bergmann,
	Sebastian Fricke, Nathan Chancellor, Hans Verkuil,
	Andrzej Pietrasiewicz, Neil Armstrong

The v4l2_m2m_get_vq() function never returns NULL.

In the set format handler, the check may have been intended to catch
invalid format types, but that's not needed as the V4L2 core picks the
appropriate VIDIOC_S_FMT ioctl handler based on the format type, so the
type can't be incorrect.

In the get format handler, the return value is not used for any purpose
other than the NULL check, which was therefore probably intended to
catch invalid format types. That's not needed for the same reason as in
the set format handler.

In other locations the v4l2_m2m_get_vq() function is called with a
hardcoded V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE type, so the NULL check
can't have been an attempt to catch an invalid type there either.

Drop the unneeded return value checks and, as the function has no side
effect, the unneeded function call as well.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 .../platform/mediatek/vcodec/decoder/mtk_vcodec_dec.c     | 7 -------
 .../mediatek/vcodec/decoder/vdec/vdec_av1_req_lat_if.c    | 2 --
 .../mediatek/vcodec/decoder/vdec/vdec_vp9_req_lat_if.c    | 2 --
 .../platform/mediatek/vcodec/encoder/mtk_vcodec_enc.c     | 8 --------
 4 files changed, 19 deletions(-)

diff --git a/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec.c b/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec.c
index 98838217b97d..a07f878b7c82 100644
--- a/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec.c
+++ b/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec.c
@@ -674,15 +674,8 @@ static int vidioc_vdec_g_fmt(struct file *file, void *priv,
 {
 	struct mtk_vcodec_dec_ctx *ctx = fh_to_dec_ctx(priv);
 	struct v4l2_pix_format_mplane *pix_mp = &f->fmt.pix_mp;
-	struct vb2_queue *vq;
 	struct mtk_q_data *q_data;
 
-	vq = v4l2_m2m_get_vq(ctx->m2m_ctx, f->type);
-	if (!vq) {
-		mtk_v4l2_vdec_err(ctx, "no vb2 queue for type=%d", f->type);
-		return -EINVAL;
-	}
-
 	q_data = mtk_vdec_get_q_data(ctx, f->type);
 
 	pix_mp->field = V4L2_FIELD_NONE;
diff --git a/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_av1_req_lat_if.c b/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_av1_req_lat_if.c
index bf21f2467a0f..08e0f5a70935 100644
--- a/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_av1_req_lat_if.c
+++ b/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_av1_req_lat_if.c
@@ -1810,8 +1810,6 @@ static int vdec_av1_slice_setup_core_buffer(struct vdec_av1_slice_instance *inst
 
 	/* reference buffers */
 	vq = v4l2_m2m_get_vq(instance->ctx->m2m_ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE);
-	if (!vq)
-		return -EINVAL;
 
 	/* get current output buffer */
 	vb = &v4l2_m2m_next_dst_buf(instance->ctx->m2m_ctx)->vb2_buf;
diff --git a/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_vp9_req_lat_if.c b/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_vp9_req_lat_if.c
index 47c302745c1d..45cd555a5fb5 100644
--- a/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_vp9_req_lat_if.c
+++ b/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_vp9_req_lat_if.c
@@ -1686,8 +1686,6 @@ static int vdec_vp9_slice_setup_core_buffer(struct vdec_vp9_slice_instance *inst
 	/* reference buffers */
 	vq = v4l2_m2m_get_vq(instance->ctx->m2m_ctx,
 			     V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE);
-	if (!vq)
-		return -EINVAL;
 
 	/* get current output buffer */
 	vb = &v4l2_m2m_next_dst_buf(instance->ctx->m2m_ctx)->vb2_buf;
diff --git a/drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc.c b/drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc.c
index a01dc25a7699..f7222c617839 100644
--- a/drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc.c
+++ b/drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc.c
@@ -422,10 +422,6 @@ static int vidioc_venc_s_fmt_cap(struct file *file, void *priv,
 	const struct mtk_video_fmt *fmt;
 
 	vq = v4l2_m2m_get_vq(ctx->m2m_ctx, f->type);
-	if (!vq) {
-		mtk_v4l2_venc_err(ctx, "fail to get vq");
-		return -EINVAL;
-	}
 
 	if (vb2_is_busy(vq)) {
 		mtk_v4l2_venc_err(ctx, "queue busy");
@@ -477,10 +473,6 @@ static int vidioc_venc_s_fmt_out(struct file *file, void *priv,
 	const struct mtk_video_fmt *fmt;
 
 	vq = v4l2_m2m_get_vq(ctx->m2m_ctx, f->type);
-	if (!vq) {
-		mtk_v4l2_venc_err(ctx, "fail to get vq");
-		return -EINVAL;
-	}
 
 	if (vb2_is_busy(vq)) {
 		mtk_v4l2_venc_err(ctx, "queue busy");
-- 
Regards,

Laurent Pinchart


^ permalink raw reply related	[flat|nested] 42+ messages in thread

* [PATCH 10/25] media: dw100: Drop unneeded v4l2_m2m_get_vq() NULL check
  2025-10-08 17:50 [PATCH 00/25] media: v4l2-mem2mem: Reduce cargo-cult Laurent Pinchart
                   ` (8 preceding siblings ...)
  2025-10-08 17:50 ` [PATCH 09/25] media: mediatek: vcodec: " Laurent Pinchart
@ 2025-10-08 17:50 ` Laurent Pinchart
  2025-10-10  8:40   ` Stefan Klug
  2025-10-08 17:50 ` [PATCH 11/25] media: imx-jpeg: " Laurent Pinchart
                   ` (15 subsequent siblings)
  25 siblings, 1 reply; 42+ messages in thread
From: Laurent Pinchart @ 2025-10-08 17:50 UTC (permalink / raw)
  To: linux-media; +Cc: Nicolas Dufresne, Xavier Roumegue

The v4l2_m2m_get_vq() function never returns NULL.

In the set format handler, the check may have been intended to catch
invalid format types, but that's not needed as the V4L2 core picks the
appropriate VIDIOC_S_FMT ioctl handler based on the format type, so the
type can't be incorrect.

In the get format handler, the return value is not used for any purpose
other than the NULL check, which was therefore probably intended to
catch invalid format types. That's not needed for the same reason as in
the set format handler.

Drop the unneeded return value checks and, as the function has no side
effect, the unneeded function call as well.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 drivers/media/platform/nxp/dw100/dw100.c | 7 -------
 1 file changed, 7 deletions(-)

diff --git a/drivers/media/platform/nxp/dw100/dw100.c b/drivers/media/platform/nxp/dw100/dw100.c
index fed1788d0702..7a0ee44d9e1f 100644
--- a/drivers/media/platform/nxp/dw100/dw100.c
+++ b/drivers/media/platform/nxp/dw100/dw100.c
@@ -765,13 +765,8 @@ static int dw100_enum_framesizes(struct file *file, void *priv,
 static int dw100_g_fmt_vid(struct file *file, void *priv, struct v4l2_format *f)
 {
 	struct dw100_ctx *ctx = dw100_file2ctx(file);
-	struct vb2_queue *vq;
 	struct dw100_q_data *q_data;
 
-	vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, f->type);
-	if (!vq)
-		return -EINVAL;
-
 	q_data = dw100_get_q_data(ctx, f->type);
 
 	f->fmt.pix_mp = q_data->pix_fmt;
@@ -833,8 +828,6 @@ static int dw100_s_fmt(struct dw100_ctx *ctx, struct v4l2_format *f)
 	struct vb2_queue *vq;
 
 	vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, f->type);
-	if (!vq)
-		return -EINVAL;
 
 	q_data = dw100_get_q_data(ctx, f->type);
 	if (!q_data)
-- 
Regards,

Laurent Pinchart


^ permalink raw reply related	[flat|nested] 42+ messages in thread

* [PATCH 11/25] media: imx-jpeg: Drop unneeded v4l2_m2m_get_vq() NULL check
  2025-10-08 17:50 [PATCH 00/25] media: v4l2-mem2mem: Reduce cargo-cult Laurent Pinchart
                   ` (9 preceding siblings ...)
  2025-10-08 17:50 ` [PATCH 10/25] media: dw100: " Laurent Pinchart
@ 2025-10-08 17:50 ` Laurent Pinchart
  2025-10-08 20:01   ` Frank Li
  2025-10-08 17:50 ` [PATCH 12/25] media: imx-pxp: " Laurent Pinchart
                   ` (14 subsequent siblings)
  25 siblings, 1 reply; 42+ messages in thread
From: Laurent Pinchart @ 2025-10-08 17:50 UTC (permalink / raw)
  To: linux-media, imx, linux-arm-kernel
  Cc: Nicolas Dufresne, Mirela Rabulea, Shawn Guo, Sascha Hauer,
	Pengutronix Kernel Team, Fabio Estevam

The v4l2_m2m_get_vq() function never returns NULL. The check may have
been intended to catch invalid format types, but that's not needed as
the V4L2 core picks the appropriate VIDIOC_S_FMT ioctl handler based on
the format type, so the type can't be incorrect. Drop the unneeded
return value check.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 drivers/media/platform/nxp/imx-jpeg/mxc-jpeg.c | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/drivers/media/platform/nxp/imx-jpeg/mxc-jpeg.c b/drivers/media/platform/nxp/imx-jpeg/mxc-jpeg.c
index 8681dd193033..37e0670f98c5 100644
--- a/drivers/media/platform/nxp/imx-jpeg/mxc-jpeg.c
+++ b/drivers/media/platform/nxp/imx-jpeg/mxc-jpeg.c
@@ -2492,8 +2492,6 @@ static int mxc_jpeg_s_fmt(struct mxc_jpeg_ctx *ctx,
 	struct mxc_jpeg_dev *jpeg = ctx->mxc_jpeg;
 
 	vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, f->type);
-	if (!vq)
-		return -EINVAL;
 
 	if (vb2_is_busy(vq)) {
 		v4l2_err(&jpeg->v4l2_dev, "queue busy\n");
@@ -2529,8 +2527,6 @@ static int mxc_jpeg_s_fmt_vid_out(struct file *file, void *priv,
 		return 0;
 
 	dst_vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, cap_type);
-	if (!dst_vq)
-		return -EINVAL;
 
 	if (vb2_is_busy(dst_vq))
 		return 0;
-- 
Regards,

Laurent Pinchart


^ permalink raw reply related	[flat|nested] 42+ messages in thread

* [PATCH 12/25] media: imx-pxp: Drop unneeded v4l2_m2m_get_vq() NULL check
  2025-10-08 17:50 [PATCH 00/25] media: v4l2-mem2mem: Reduce cargo-cult Laurent Pinchart
                   ` (10 preceding siblings ...)
  2025-10-08 17:50 ` [PATCH 11/25] media: imx-jpeg: " Laurent Pinchart
@ 2025-10-08 17:50 ` 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
                   ` (13 subsequent siblings)
  25 siblings, 2 replies; 42+ messages in thread
From: Laurent Pinchart @ 2025-10-08 17:50 UTC (permalink / raw)
  To: linux-media, imx, linux-arm-kernel
  Cc: Nicolas Dufresne, Philipp Zabel, Shawn Guo, Sascha Hauer,
	Pengutronix Kernel Team, Fabio Estevam

The v4l2_m2m_get_vq() function never returns NULL.

In the set format handler, the check may have been intended to catch
invalid format types, but that's not needed as the V4L2 core picks the
appropriate VIDIOC_S_FMT ioctl handler based on the format type, so the
type can't be incorrect.

In the get format handler, the return value is not used for any purpose
other than the NULL check, which was therefore probably intended to
catch invalid format types. That's not needed for the same reason as in
the set format handler.

Drop the unneeded return value checks and, as the function has no side
effect, the unneeded function call as well.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 drivers/media/platform/nxp/imx-pxp.c | 7 -------
 1 file changed, 7 deletions(-)

diff --git a/drivers/media/platform/nxp/imx-pxp.c b/drivers/media/platform/nxp/imx-pxp.c
index 7f8ffbac582f..5386650ce194 100644
--- a/drivers/media/platform/nxp/imx-pxp.c
+++ b/drivers/media/platform/nxp/imx-pxp.c
@@ -1180,13 +1180,8 @@ static int pxp_enum_fmt_vid_out(struct file *file, void *priv,
 
 static int pxp_g_fmt(struct pxp_ctx *ctx, struct v4l2_format *f)
 {
-	struct vb2_queue *vq;
 	struct pxp_q_data *q_data;
 
-	vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, f->type);
-	if (!vq)
-		return -EINVAL;
-
 	q_data = get_q_data(ctx, f->type);
 
 	f->fmt.pix.width	= q_data->width;
@@ -1329,8 +1324,6 @@ static int pxp_s_fmt(struct pxp_ctx *ctx, struct v4l2_format *f)
 	struct vb2_queue *vq;
 
 	vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, f->type);
-	if (!vq)
-		return -EINVAL;
 
 	q_data = get_q_data(ctx, f->type);
 	if (!q_data)
-- 
Regards,

Laurent Pinchart


^ permalink raw reply related	[flat|nested] 42+ messages in thread

* [PATCH 13/25] media: nxp: imx8-isi: Drop unneeded v4l2_m2m_get_vq() NULL check
  2025-10-08 17:50 [PATCH 00/25] media: v4l2-mem2mem: Reduce cargo-cult Laurent Pinchart
                   ` (11 preceding siblings ...)
  2025-10-08 17:50 ` [PATCH 12/25] media: imx-pxp: " Laurent Pinchart
@ 2025-10-08 17:50 ` Laurent Pinchart
  2025-10-08 20:02   ` Frank Li
  2025-10-08 17:50 ` [PATCH 14/25] media: mx2_emmaprp: " Laurent Pinchart
                   ` (12 subsequent siblings)
  25 siblings, 1 reply; 42+ messages in thread
From: Laurent Pinchart @ 2025-10-08 17:50 UTC (permalink / raw)
  To: linux-media, imx, linux-arm-kernel
  Cc: Nicolas Dufresne, Shawn Guo, Sascha Hauer,
	Pengutronix Kernel Team, Fabio Estevam

The v4l2_m2m_get_vq() function never returns NULL. The check may have
been intended to catch invalid format types, but that's not needed as
the V4L2 core picks the appropriate VIDIOC_S_FMT ioctl handler based on
the format type, so the type can't be incorrect. Drop the unneeded
return value check.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 drivers/media/platform/nxp/imx8-isi/imx8-isi-m2m.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/media/platform/nxp/imx8-isi/imx8-isi-m2m.c b/drivers/media/platform/nxp/imx8-isi/imx8-isi-m2m.c
index 6822c2f7fc69..675f1d2b65d9 100644
--- a/drivers/media/platform/nxp/imx8-isi/imx8-isi-m2m.c
+++ b/drivers/media/platform/nxp/imx8-isi/imx8-isi-m2m.c
@@ -554,8 +554,6 @@ static int mxc_isi_m2m_s_fmt_vid(struct file *file, void *fh,
 	struct vb2_queue *vq;
 
 	vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, f->type);
-	if (!vq)
-		return -EINVAL;
 
 	if (vb2_is_busy(vq))
 		return -EBUSY;
-- 
Regards,

Laurent Pinchart


^ permalink raw reply related	[flat|nested] 42+ messages in thread

* [PATCH 14/25] media: mx2_emmaprp: Drop unneeded v4l2_m2m_get_vq() NULL check
  2025-10-08 17:50 [PATCH 00/25] media: v4l2-mem2mem: Reduce cargo-cult Laurent Pinchart
                   ` (12 preceding siblings ...)
  2025-10-08 17:50 ` [PATCH 13/25] media: nxp: imx8-isi: " Laurent Pinchart
@ 2025-10-08 17:50 ` Laurent Pinchart
  2025-10-08 17:50 ` [PATCH 15/25] media: qcom: iris: " Laurent Pinchart
                   ` (11 subsequent siblings)
  25 siblings, 0 replies; 42+ messages in thread
From: Laurent Pinchart @ 2025-10-08 17:50 UTC (permalink / raw)
  To: linux-media
  Cc: Nicolas Dufresne, Hans Verkuil, Uwe Kleine-König,
	Andrzej Pietrasiewicz, Neil Armstrong

The v4l2_m2m_get_vq() function never returns NULL.

In the set format handler, the check may have been intended to catch
invalid format types, but that's not needed as the V4L2 core picks the
appropriate VIDIOC_S_FMT ioctl handler based on the format type, so the
type can't be incorrect.

In the get format handler, the return value is not used for any purpose
other than the NULL check, which was therefore probably intended to
catch invalid format types. That's not needed for the same reason as in
the set format handler.

Drop the unneeded return value checks and, as the function has no side
effect, the unneeded function call as well.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 drivers/media/platform/nxp/mx2_emmaprp.c | 7 -------
 1 file changed, 7 deletions(-)

diff --git a/drivers/media/platform/nxp/mx2_emmaprp.c b/drivers/media/platform/nxp/mx2_emmaprp.c
index 0c6cc120fd2a..bdc2f54c8f45 100644
--- a/drivers/media/platform/nxp/mx2_emmaprp.c
+++ b/drivers/media/platform/nxp/mx2_emmaprp.c
@@ -426,13 +426,8 @@ static int vidioc_enum_fmt_vid_out(struct file *file, void *priv,
 
 static int vidioc_g_fmt(struct emmaprp_ctx *ctx, struct v4l2_format *f)
 {
-	struct vb2_queue *vq;
 	struct emmaprp_q_data *q_data;
 
-	vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, f->type);
-	if (!vq)
-		return -EINVAL;
-
 	q_data = get_q_data(ctx, f->type);
 
 	f->fmt.pix.width	= q_data->width;
@@ -535,8 +530,6 @@ static int vidioc_s_fmt(struct emmaprp_ctx *ctx, struct v4l2_format *f)
 	int ret;
 
 	vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, f->type);
-	if (!vq)
-		return -EINVAL;
 
 	q_data = get_q_data(ctx, f->type);
 	if (!q_data)
-- 
Regards,

Laurent Pinchart


^ permalink raw reply related	[flat|nested] 42+ messages in thread

* [PATCH 15/25] media: qcom: iris: Drop unneeded v4l2_m2m_get_vq() NULL check
  2025-10-08 17:50 [PATCH 00/25] media: v4l2-mem2mem: Reduce cargo-cult Laurent Pinchart
                   ` (13 preceding siblings ...)
  2025-10-08 17:50 ` [PATCH 14/25] media: mx2_emmaprp: " Laurent Pinchart
@ 2025-10-08 17:50 ` Laurent Pinchart
  2025-10-08 23:51   ` Bryan O'Donoghue
  2025-10-09 13:53   ` Dikshita Agarwal
  2025-10-08 17:50 ` [PATCH 16/25] media: qcom: venus: " Laurent Pinchart
                   ` (10 subsequent siblings)
  25 siblings, 2 replies; 42+ messages in thread
From: Laurent Pinchart @ 2025-10-08 17:50 UTC (permalink / raw)
  To: linux-media, linux-arm-msm
  Cc: Nicolas Dufresne, Vikash Garodia, Dikshita Agarwal, Abhinav Kumar,
	Bryan O'Donoghue

The v4l2_m2m_get_vq() function never returns NULL. The check may have
been intended to catch invalid format types, but that's not needed as
the V4L2 core picks the appropriate VIDIOC_S_FMT ioctl handler based on
the format type, so the type can't be incorrect. Drop the unneeded
return value check.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 drivers/media/platform/qcom/iris/iris_vdec.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/media/platform/qcom/iris/iris_vdec.c b/drivers/media/platform/qcom/iris/iris_vdec.c
index d670b51c5839..1e9ffdbb6e18 100644
--- a/drivers/media/platform/qcom/iris/iris_vdec.c
+++ b/drivers/media/platform/qcom/iris/iris_vdec.c
@@ -191,8 +191,6 @@ int iris_vdec_s_fmt(struct iris_inst *inst, struct v4l2_format *f)
 	u32 codec_align;
 
 	q = v4l2_m2m_get_vq(inst->m2m_ctx, f->type);
-	if (!q)
-		return -EINVAL;
 
 	if (vb2_is_busy(q))
 		return -EBUSY;
-- 
Regards,

Laurent Pinchart


^ permalink raw reply related	[flat|nested] 42+ messages in thread

* [PATCH 16/25] media: qcom: venus: Drop unneeded v4l2_m2m_get_vq() NULL check
  2025-10-08 17:50 [PATCH 00/25] media: v4l2-mem2mem: Reduce cargo-cult Laurent Pinchart
                   ` (14 preceding siblings ...)
  2025-10-08 17:50 ` [PATCH 15/25] media: qcom: iris: " Laurent Pinchart
@ 2025-10-08 17:50 ` 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
                   ` (9 subsequent siblings)
  25 siblings, 2 replies; 42+ messages in thread
From: Laurent Pinchart @ 2025-10-08 17:50 UTC (permalink / raw)
  To: linux-media, linux-arm-msm
  Cc: Nicolas Dufresne, Vikash Garodia, Dikshita Agarwal,
	Bryan O'Donoghue

The v4l2_m2m_get_vq() function never returns NULL. The check may have
been intended to catch invalid format types, but that's not needed as
the V4L2 core picks the appropriate VIDIOC_S_FMT ioctl handler based on
the format type, so the type can't be incorrect. Drop the unneeded
return value check.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 drivers/media/platform/qcom/venus/vdec.c | 2 --
 drivers/media/platform/qcom/venus/venc.c | 2 --
 2 files changed, 4 deletions(-)

diff --git a/drivers/media/platform/qcom/venus/vdec.c b/drivers/media/platform/qcom/venus/vdec.c
index 29b0d6a5303d..8c77db0f6e76 100644
--- a/drivers/media/platform/qcom/venus/vdec.c
+++ b/drivers/media/platform/qcom/venus/vdec.c
@@ -329,8 +329,6 @@ static int vdec_s_fmt(struct file *file, void *fh, struct v4l2_format *f)
 	struct vb2_queue *q;
 
 	q = v4l2_m2m_get_vq(inst->m2m_ctx, f->type);
-	if (!q)
-		return -EINVAL;
 
 	if (vb2_is_busy(q))
 		return -EBUSY;
diff --git a/drivers/media/platform/qcom/venus/venc.c b/drivers/media/platform/qcom/venus/venc.c
index c0a0ccdded80..0fe4cc37118b 100644
--- a/drivers/media/platform/qcom/venus/venc.c
+++ b/drivers/media/platform/qcom/venus/venc.c
@@ -241,8 +241,6 @@ static int venc_s_fmt(struct file *file, void *fh, struct v4l2_format *f)
 	struct vb2_queue *q;
 
 	q = v4l2_m2m_get_vq(inst->m2m_ctx, f->type);
-	if (!q)
-		return -EINVAL;
 
 	if (vb2_is_busy(q))
 		return -EBUSY;
-- 
Regards,

Laurent Pinchart


^ permalink raw reply related	[flat|nested] 42+ messages in thread

* [PATCH 17/25] media: renesas: fdp1: Drop unneeded v4l2_m2m_get_vq() NULL check
  2025-10-08 17:50 [PATCH 00/25] media: v4l2-mem2mem: Reduce cargo-cult Laurent Pinchart
                   ` (15 preceding siblings ...)
  2025-10-08 17:50 ` [PATCH 16/25] media: qcom: venus: " Laurent Pinchart
@ 2025-10-08 17:50 ` Laurent Pinchart
  2025-10-08 17:50 ` [PATCH 18/25] media: rcar_jpu: " Laurent Pinchart
                   ` (8 subsequent siblings)
  25 siblings, 0 replies; 42+ messages in thread
From: Laurent Pinchart @ 2025-10-08 17:50 UTC (permalink / raw)
  To: linux-media, linux-renesas-soc
  Cc: Nicolas Dufresne, Kieran Bingham, Geert Uytterhoeven, Magnus Damm

The v4l2_m2m_get_vq() function never returns NULL. The check was
probably intended to catch invalid format types, but that's not needed
as the V4L2 core picks the appropriate VIDIOC_G_FMT ioctl handler based
on the format type, so the type can't be incorrect. Drop the unneeded
return value check and, as the function has no side effect, the function
call as well.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 drivers/media/platform/renesas/rcar_fdp1.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/drivers/media/platform/renesas/rcar_fdp1.c b/drivers/media/platform/renesas/rcar_fdp1.c
index 5d453a7a8988..e260d31e3a9f 100644
--- a/drivers/media/platform/renesas/rcar_fdp1.c
+++ b/drivers/media/platform/renesas/rcar_fdp1.c
@@ -1409,9 +1409,6 @@ static int fdp1_g_fmt(struct file *file, void *priv, struct v4l2_format *f)
 	struct fdp1_q_data *q_data;
 	struct fdp1_ctx *ctx = fh_to_ctx(priv);
 
-	if (!v4l2_m2m_get_vq(ctx->fh.m2m_ctx, f->type))
-		return -EINVAL;
-
 	q_data = get_q_data(ctx, f->type);
 	f->fmt.pix_mp = q_data->format;
 
-- 
Regards,

Laurent Pinchart


^ permalink raw reply related	[flat|nested] 42+ messages in thread

* [PATCH 18/25] media: rcar_jpu: Drop unneeded v4l2_m2m_get_vq() NULL check
  2025-10-08 17:50 [PATCH 00/25] media: v4l2-mem2mem: Reduce cargo-cult Laurent Pinchart
                   ` (16 preceding siblings ...)
  2025-10-08 17:50 ` [PATCH 17/25] media: renesas: fdp1: " Laurent Pinchart
@ 2025-10-08 17:50 ` Laurent Pinchart
  2025-10-08 17:50 ` [PATCH 19/25] media: platform: rga: " Laurent Pinchart
                   ` (7 subsequent siblings)
  25 siblings, 0 replies; 42+ messages in thread
From: Laurent Pinchart @ 2025-10-08 17:50 UTC (permalink / raw)
  To: linux-media, linux-renesas-soc
  Cc: Nicolas Dufresne, Mikhail Ulyanov, Geert Uytterhoeven,
	Magnus Damm

The v4l2_m2m_get_vq() function never returns NULL.

In the set format handler, the check may have been intended to catch
invalid format types, but that's not needed as the V4L2 core picks the
appropriate VIDIOC_S_FMT ioctl handler based on the format type, so the
type can't be incorrect.

In the get and try format handlers, the return value is not used for any
purpose other than the NULL check, which was therefore probably intended
to catch invalid format types. That's not needed for the same reason as
in the set format handler.

Drop the unneeded return value check and, as the function has no side
effect, the unneeded function calls as well.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 drivers/media/platform/renesas/rcar_jpu.c | 8 --------
 1 file changed, 8 deletions(-)

diff --git a/drivers/media/platform/renesas/rcar_jpu.c b/drivers/media/platform/renesas/rcar_jpu.c
index 81038df71bb5..5a4376bdd10f 100644
--- a/drivers/media/platform/renesas/rcar_jpu.c
+++ b/drivers/media/platform/renesas/rcar_jpu.c
@@ -825,9 +825,6 @@ static int jpu_try_fmt(struct file *file, void *priv, struct v4l2_format *f)
 {
 	struct jpu_ctx *ctx = fh_to_ctx(priv);
 
-	if (!v4l2_m2m_get_vq(ctx->fh.m2m_ctx, f->type))
-		return -EINVAL;
-
 	return __jpu_try_fmt(ctx, NULL, &f->fmt.pix_mp, f->type);
 }
 
@@ -841,8 +838,6 @@ static int jpu_s_fmt(struct file *file, void *priv, struct v4l2_format *f)
 	int ret;
 
 	vq = v4l2_m2m_get_vq(m2m_ctx, f->type);
-	if (!vq)
-		return -EINVAL;
 
 	if (vb2_is_busy(vq)) {
 		v4l2_err(&ctx->jpu->v4l2_dev, "%s queue busy\n", __func__);
@@ -866,9 +861,6 @@ static int jpu_g_fmt(struct file *file, void *priv, struct v4l2_format *f)
 	struct jpu_q_data *q_data;
 	struct jpu_ctx *ctx = fh_to_ctx(priv);
 
-	if (!v4l2_m2m_get_vq(ctx->fh.m2m_ctx, f->type))
-		return -EINVAL;
-
 	q_data = jpu_get_q_data(ctx, f->type);
 	f->fmt.pix_mp = q_data->format;
 
-- 
Regards,

Laurent Pinchart


^ permalink raw reply related	[flat|nested] 42+ messages in thread

* [PATCH 19/25] media: platform: rga: Drop unneeded v4l2_m2m_get_vq() NULL check
  2025-10-08 17:50 [PATCH 00/25] media: v4l2-mem2mem: Reduce cargo-cult Laurent Pinchart
                   ` (17 preceding siblings ...)
  2025-10-08 17:50 ` [PATCH 18/25] media: rcar_jpu: " Laurent Pinchart
@ 2025-10-08 17:50 ` Laurent Pinchart
  2025-10-08 17:50 ` [PATCH 20/25] media: samsung: s5p-g2d: " Laurent Pinchart
                   ` (6 subsequent siblings)
  25 siblings, 0 replies; 42+ messages in thread
From: Laurent Pinchart @ 2025-10-08 17:50 UTC (permalink / raw)
  To: linux-media, linux-rockchip, linux-arm-kernel
  Cc: Nicolas Dufresne, Jacob Chen, Ezequiel Garcia, Heiko Stuebner

The v4l2_m2m_get_vq() function never returns NULL. The check was
probably intended to catch invalid format types, but that's not needed
as the V4L2 core picks the appropriate VIDIOC_G_FMT ioctl handler based
on the format type, so the type can't be incorrect. Drop the unneeded
return value check and, as the return value is not used for other
purposes and the function has no side effect, the function call as well.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 drivers/media/platform/rockchip/rga/rga.c | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/drivers/media/platform/rockchip/rga/rga.c b/drivers/media/platform/rockchip/rga/rga.c
index 3dccab5fa4a1..48b88da59da0 100644
--- a/drivers/media/platform/rockchip/rga/rga.c
+++ b/drivers/media/platform/rockchip/rga/rga.c
@@ -465,12 +465,8 @@ static int vidioc_g_fmt(struct file *file, void *prv, struct v4l2_format *f)
 {
 	struct v4l2_pix_format_mplane *pix_fmt = &f->fmt.pix_mp;
 	struct rga_ctx *ctx = prv;
-	struct vb2_queue *vq;
 	struct rga_frame *frm;
 
-	vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, f->type);
-	if (!vq)
-		return -EINVAL;
 	frm = rga_get_frame(ctx, f->type);
 	if (IS_ERR(frm))
 		return PTR_ERR(frm);
-- 
Regards,

Laurent Pinchart


^ permalink raw reply related	[flat|nested] 42+ messages in thread

* [PATCH 20/25] media: samsung: s5p-g2d: Drop unneeded v4l2_m2m_get_vq() NULL check
  2025-10-08 17:50 [PATCH 00/25] media: v4l2-mem2mem: Reduce cargo-cult Laurent Pinchart
                   ` (18 preceding siblings ...)
  2025-10-08 17:50 ` [PATCH 19/25] media: platform: rga: " Laurent Pinchart
@ 2025-10-08 17:50 ` Laurent Pinchart
  2025-10-10 11:00   ` Lukasz Stelmach
  2025-10-08 17:50 ` [PATCH 21/25] media: samsung: s5p-jpeg: " Laurent Pinchart
                   ` (5 subsequent siblings)
  25 siblings, 1 reply; 42+ messages in thread
From: Laurent Pinchart @ 2025-10-08 17:50 UTC (permalink / raw)
  To: linux-media, linux-arm-kernel; +Cc: Nicolas Dufresne, Łukasz Stelmach

The v4l2_m2m_get_vq() function never returns NULL. The check was
probably intended to catch invalid format types, but that's not needed
as the V4L2 core picks the appropriate VIDIOC_G_FMT ioctl handler based
on the format type, so the type can't be incorrect. Drop the unneeded
return value check and, as the return value is not used for other
purposes and the function has no side effect, the function call as well.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 drivers/media/platform/samsung/s5p-g2d/g2d.c | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/drivers/media/platform/samsung/s5p-g2d/g2d.c b/drivers/media/platform/samsung/s5p-g2d/g2d.c
index ffed16a34493..7b0481c7f953 100644
--- a/drivers/media/platform/samsung/s5p-g2d/g2d.c
+++ b/drivers/media/platform/samsung/s5p-g2d/g2d.c
@@ -306,12 +306,8 @@ static int vidioc_enum_fmt(struct file *file, void *prv, struct v4l2_fmtdesc *f)
 static int vidioc_g_fmt(struct file *file, void *prv, struct v4l2_format *f)
 {
 	struct g2d_ctx *ctx = prv;
-	struct vb2_queue *vq;
 	struct g2d_frame *frm;
 
-	vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, f->type);
-	if (!vq)
-		return -EINVAL;
 	frm = get_frame(ctx, f->type);
 	if (IS_ERR(frm))
 		return PTR_ERR(frm);
-- 
Regards,

Laurent Pinchart


^ permalink raw reply related	[flat|nested] 42+ messages in thread

* [PATCH 21/25] media: samsung: s5p-jpeg: Drop unneeded v4l2_m2m_get_vq() NULL check
  2025-10-08 17:50 [PATCH 00/25] media: v4l2-mem2mem: Reduce cargo-cult Laurent Pinchart
                   ` (19 preceding siblings ...)
  2025-10-08 17:50 ` [PATCH 20/25] media: samsung: s5p-g2d: " Laurent Pinchart
@ 2025-10-08 17:50 ` Laurent Pinchart
  2025-10-08 17:50 ` [PATCH 22/25] media: stm32: dma2d: " Laurent Pinchart
                   ` (4 subsequent siblings)
  25 siblings, 0 replies; 42+ messages in thread
From: Laurent Pinchart @ 2025-10-08 17:50 UTC (permalink / raw)
  To: linux-media, linux-arm-kernel
  Cc: Nicolas Dufresne, Andrzej Pietrasiewicz, Jacek Anaszewski,
	Sylwester Nawrocki

The v4l2_m2m_get_vq() function never returns NULL.

In the set format handler, the check may have been intended to catch
invalid format types, but that's not needed as the V4L2 core picks the
appropriate VIDIOC_S_FMT ioctl handler based on the format type, so the
type can't be incorrect.

In the get format handler, the return value is not used for any purpose
other than the NULL check, which was therefore probably intended to
catch invalid format types. That's not needed for the same reason as in
the set format handler.

Drop the unneeded return value check and, as the function has no side
effect, the unneeded function call as well.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 drivers/media/platform/samsung/s5p-jpeg/jpeg-core.c | 7 -------
 1 file changed, 7 deletions(-)

diff --git a/drivers/media/platform/samsung/s5p-jpeg/jpeg-core.c b/drivers/media/platform/samsung/s5p-jpeg/jpeg-core.c
index ac4cf269456a..3211e9d0fda7 100644
--- a/drivers/media/platform/samsung/s5p-jpeg/jpeg-core.c
+++ b/drivers/media/platform/samsung/s5p-jpeg/jpeg-core.c
@@ -1333,15 +1333,10 @@ static struct s5p_jpeg_q_data *get_q_data(struct s5p_jpeg_ctx *ctx,
 
 static int s5p_jpeg_g_fmt(struct file *file, void *priv, struct v4l2_format *f)
 {
-	struct vb2_queue *vq;
 	struct s5p_jpeg_q_data *q_data = NULL;
 	struct v4l2_pix_format *pix = &f->fmt.pix;
 	struct s5p_jpeg_ctx *ct = fh_to_ctx(priv);
 
-	vq = v4l2_m2m_get_vq(ct->fh.m2m_ctx, f->type);
-	if (!vq)
-		return -EINVAL;
-
 	if (f->type == V4L2_BUF_TYPE_VIDEO_CAPTURE &&
 	    ct->mode == S5P_JPEG_DECODE && !ct->hdr_parsed)
 		return -EINVAL;
@@ -1594,8 +1589,6 @@ static int s5p_jpeg_s_fmt(struct s5p_jpeg_ctx *ct, struct v4l2_format *f)
 	unsigned int f_type;
 
 	vq = v4l2_m2m_get_vq(ct->fh.m2m_ctx, f->type);
-	if (!vq)
-		return -EINVAL;
 
 	q_data = get_q_data(ct, f->type);
 	BUG_ON(q_data == NULL);
-- 
Regards,

Laurent Pinchart


^ permalink raw reply related	[flat|nested] 42+ messages in thread

* [PATCH 22/25] media: stm32: dma2d: Drop unneeded v4l2_m2m_get_vq() NULL check
  2025-10-08 17:50 [PATCH 00/25] media: v4l2-mem2mem: Reduce cargo-cult Laurent Pinchart
                   ` (20 preceding siblings ...)
  2025-10-08 17:50 ` [PATCH 21/25] media: samsung: s5p-jpeg: " Laurent Pinchart
@ 2025-10-08 17:50 ` Laurent Pinchart
  2025-10-08 17:50 ` [PATCH 23/25] media: ti: vpe: " Laurent Pinchart
                   ` (3 subsequent siblings)
  25 siblings, 0 replies; 42+ messages in thread
From: Laurent Pinchart @ 2025-10-08 17:50 UTC (permalink / raw)
  To: linux-media, linux-stm32, linux-arm-kernel
  Cc: Nicolas Dufresne, Maxime Coquelin, Alexandre Torgue, Hans Verkuil,
	Jiasheng Jiang, Uwe Kleine-König, Andrzej Pietrasiewicz

The v4l2_m2m_get_vq() function never returns NULL. The check was
probably intended to catch invalid format types, but that's not needed
as the V4L2 core picks the appropriate VIDIOC_G_FMT ioctl handler based
on the format type, so the type can't be incorrect. Drop the unneeded
return value check and, as the return value is not used for other
purposes and the function has no side effect, the function call as well.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 drivers/media/platform/st/stm32/dma2d/dma2d.c | 5 -----
 1 file changed, 5 deletions(-)

diff --git a/drivers/media/platform/st/stm32/dma2d/dma2d.c b/drivers/media/platform/st/stm32/dma2d/dma2d.c
index 48fa781aab06..643913adc1f3 100644
--- a/drivers/media/platform/st/stm32/dma2d/dma2d.c
+++ b/drivers/media/platform/st/stm32/dma2d/dma2d.c
@@ -353,13 +353,8 @@ static int vidioc_enum_fmt(struct file *file, void *prv, struct v4l2_fmtdesc *f)
 static int vidioc_g_fmt(struct file *file, void *prv, struct v4l2_format *f)
 {
 	struct dma2d_ctx *ctx = prv;
-	struct vb2_queue *vq;
 	struct dma2d_frame *frm;
 
-	vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, f->type);
-	if (!vq)
-		return -EINVAL;
-
 	frm = get_frame(ctx, f->type);
 	f->fmt.pix.width		= frm->width;
 	f->fmt.pix.height		= frm->height;
-- 
Regards,

Laurent Pinchart


^ permalink raw reply related	[flat|nested] 42+ messages in thread

* [PATCH 23/25] media: ti: vpe: Drop unneeded v4l2_m2m_get_vq() NULL check
  2025-10-08 17:50 [PATCH 00/25] media: v4l2-mem2mem: Reduce cargo-cult Laurent Pinchart
                   ` (21 preceding siblings ...)
  2025-10-08 17:50 ` [PATCH 22/25] media: stm32: dma2d: " Laurent Pinchart
@ 2025-10-08 17:50 ` Laurent Pinchart
  2025-10-08 17:50 ` [PATCH 24/25] media: vicodec: " Laurent Pinchart
                   ` (2 subsequent siblings)
  25 siblings, 0 replies; 42+ messages in thread
From: Laurent Pinchart @ 2025-10-08 17:50 UTC (permalink / raw)
  To: linux-media; +Cc: Nicolas Dufresne, Benoit Parrot

The v4l2_m2m_get_vq() function never returns NULL.

In the set format handler, the check may have been intended to catch
invalid format types, but that's not needed as the V4L2 core picks the
appropriate VIDIOC_S_FMT ioctl handler based on the format type, so the
type can't be incorrect.

In the get format handler, the return value is not used for any purpose
other than the NULL check, which was therefore probably intended to
catch invalid format types. That's not needed for the same reason as in
the set format handler.

Drop the unneeded return value checks and, as the function has no side
effect, the unneeded function call as well.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 drivers/media/platform/ti/vpe/vpe.c | 7 -------
 1 file changed, 7 deletions(-)

diff --git a/drivers/media/platform/ti/vpe/vpe.c b/drivers/media/platform/ti/vpe/vpe.c
index 636d76ecebcd..70cb430b099c 100644
--- a/drivers/media/platform/ti/vpe/vpe.c
+++ b/drivers/media/platform/ti/vpe/vpe.c
@@ -1563,13 +1563,8 @@ static int vpe_g_fmt(struct file *file, void *priv, struct v4l2_format *f)
 {
 	struct v4l2_pix_format_mplane *pix = &f->fmt.pix_mp;
 	struct vpe_ctx *ctx = file->private_data;
-	struct vb2_queue *vq;
 	struct vpe_q_data *q_data;
 
-	vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, f->type);
-	if (!vq)
-		return -EINVAL;
-
 	q_data = get_q_data(ctx, f->type);
 	if (!q_data)
 		return -EINVAL;
@@ -1736,8 +1731,6 @@ static int __vpe_s_fmt(struct vpe_ctx *ctx, struct v4l2_format *f)
 	struct vb2_queue *vq;
 
 	vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, f->type);
-	if (!vq)
-		return -EINVAL;
 
 	if (vb2_is_busy(vq)) {
 		vpe_err(ctx->dev, "queue busy\n");
-- 
Regards,

Laurent Pinchart


^ permalink raw reply related	[flat|nested] 42+ messages in thread

* [PATCH 24/25] media: vicodec: Drop unneeded v4l2_m2m_get_vq() NULL check
  2025-10-08 17:50 [PATCH 00/25] media: v4l2-mem2mem: Reduce cargo-cult Laurent Pinchart
                   ` (22 preceding siblings ...)
  2025-10-08 17:50 ` [PATCH 23/25] media: ti: vpe: " Laurent Pinchart
@ 2025-10-08 17:50 ` 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
  25 siblings, 0 replies; 42+ messages in thread
From: Laurent Pinchart @ 2025-10-08 17:50 UTC (permalink / raw)
  To: linux-media; +Cc: Nicolas Dufresne, Hans Verkuil

The v4l2_m2m_get_vq() function never returns NULL.

In the set format handler, the check may have been intended to catch
invalid format types, but that's not needed as the V4L2 core picks the
appropriate VIDIOC_S_FMT ioctl handler based on the format type, so the
type can't be incorrect.

In the get format handler, the return value is not used for any purpose
other than the NULL check, which was therefore probably intended to
catch invalid format types. That's not needed for the same reason as in
the set format handler.

Drop the unneeded return value checks and, as the function has no side
effect, the unneeded function call as well.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 drivers/media/test-drivers/vicodec/vicodec-core.c | 7 -------
 1 file changed, 7 deletions(-)

diff --git a/drivers/media/test-drivers/vicodec/vicodec-core.c b/drivers/media/test-drivers/vicodec/vicodec-core.c
index c45f5cf12ded..e4271873e4ec 100644
--- a/drivers/media/test-drivers/vicodec/vicodec-core.c
+++ b/drivers/media/test-drivers/vicodec/vicodec-core.c
@@ -760,16 +760,11 @@ static int vidioc_enum_fmt_vid_out(struct file *file, void *priv,
 
 static int vidioc_g_fmt(struct vicodec_ctx *ctx, struct v4l2_format *f)
 {
-	struct vb2_queue *vq;
 	struct vicodec_q_data *q_data;
 	struct v4l2_pix_format_mplane *pix_mp;
 	struct v4l2_pix_format *pix;
 	const struct v4l2_fwht_pixfmt_info *info;
 
-	vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, f->type);
-	if (!vq)
-		return -EINVAL;
-
 	q_data = get_q_data(ctx, f->type);
 	info = q_data->info;
 
@@ -976,8 +971,6 @@ static int vidioc_s_fmt(struct vicodec_ctx *ctx, struct v4l2_format *f)
 	struct v4l2_pix_format *pix;
 
 	vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, f->type);
-	if (!vq)
-		return -EINVAL;
 
 	q_data = get_q_data(ctx, f->type);
 	if (!q_data)
-- 
Regards,

Laurent Pinchart


^ permalink raw reply related	[flat|nested] 42+ messages in thread

* [PATCH 25/25] media: vim2m: Drop unneeded v4l2_m2m_get_vq() NULL check
  2025-10-08 17:50 [PATCH 00/25] media: v4l2-mem2mem: Reduce cargo-cult Laurent Pinchart
                   ` (23 preceding siblings ...)
  2025-10-08 17:50 ` [PATCH 24/25] media: vicodec: " Laurent Pinchart
@ 2025-10-08 17:50 ` Laurent Pinchart
  2025-10-08 18:24 ` [PATCH 00/25] media: v4l2-mem2mem: Reduce cargo-cult Nicolas Dufresne
  25 siblings, 0 replies; 42+ messages in thread
From: Laurent Pinchart @ 2025-10-08 17:50 UTC (permalink / raw)
  To: linux-media
  Cc: Nicolas Dufresne, Hans Verkuil, Matthew Majewski,
	Uwe Kleine-König, Shuah Khan

The v4l2_m2m_get_vq() function never returns NULL.

In the set format handler, the check may have been intended to catch
invalid format types, but that's not needed as the V4L2 core picks the
appropriate VIDIOC_S_FMT ioctl handler based on the format type, so the
type can't be incorrect.

In the get format handler, the return value is not used for any purpose
other than the NULL check, which was therefore probably intended to
catch invalid format types. That's not needed for the same reason as in
the set format handler.

Drop the unneeded return value checks and, as the function has no side
effect, the unneeded function call as well.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 drivers/media/test-drivers/vim2m.c | 12 ------------
 1 file changed, 12 deletions(-)

diff --git a/drivers/media/test-drivers/vim2m.c b/drivers/media/test-drivers/vim2m.c
index 1d1a9e768505..dc82830a35a5 100644
--- a/drivers/media/test-drivers/vim2m.c
+++ b/drivers/media/test-drivers/vim2m.c
@@ -729,14 +729,9 @@ static int vidioc_enum_framesizes(struct file *file, void *priv,
 
 static int vidioc_g_fmt(struct vim2m_ctx *ctx, struct v4l2_format *f)
 {
-	struct vb2_queue *vq;
 	struct vim2m_q_data *q_data;
 	int ret;
 
-	vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, f->type);
-	if (!vq)
-		return -EINVAL;
-
 	q_data = get_q_data(ctx, f->type);
 	if (!q_data)
 		return -EINVAL;
@@ -757,14 +752,9 @@ static int vidioc_g_fmt(struct vim2m_ctx *ctx, struct v4l2_format *f)
 
 static int vidioc_g_fmt_mplane(struct vim2m_ctx *ctx, struct v4l2_format *f)
 {
-	struct vb2_queue *vq;
 	struct vim2m_q_data *q_data;
 	int ret;
 
-	vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, f->type);
-	if (!vq)
-		return -EINVAL;
-
 	q_data = get_q_data(ctx, f->type);
 	if (!q_data)
 		return -EINVAL;
@@ -976,8 +966,6 @@ static int vidioc_s_fmt(struct vim2m_ctx *ctx, struct v4l2_format *f)
 	u32 height = (is_mplane) ? f->fmt.pix_mp.height : f->fmt.pix.height;
 
 	vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, f->type);
-	if (!vq)
-		return -EINVAL;
 
 	q_data = get_q_data(ctx, f->type);
 	if (!q_data)
-- 
Regards,

Laurent Pinchart


^ permalink raw reply related	[flat|nested] 42+ messages in thread

* Re: [PATCH 03/25] media: meson-g2d: Drop unneeded v4l2_m2m_get_vq() NULL check
  2025-10-08 17:50 ` [PATCH 03/25] media: meson-g2d: " Laurent Pinchart
@ 2025-10-08 18:13   ` Neil Armstrong
  0 siblings, 0 replies; 42+ messages in thread
From: Neil Armstrong @ 2025-10-08 18:13 UTC (permalink / raw)
  To: Laurent Pinchart, linux-media, linux-amlogic, linux-arm-kernel
  Cc: Nicolas Dufresne, Kevin Hilman, Jerome Brunet,
	Martin Blumenstingl

On 10/8/25 19:50, Laurent Pinchart wrote:
> The v4l2_m2m_get_vq() function never returns NULL. The check was
> probably intended to catch invalid format types, but that's not needed
> as the V4L2 core picks the appropriate VIDIOC_G_FMT ioctl handler based
> on the format type, so the type can't be incorrect. Drop the unneeded
> return value check and, as the return value is not used for other
> purposes and the function has no side effect, the function call as well.
> 
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> ---
>   drivers/media/platform/amlogic/meson-ge2d/ge2d.c | 5 -----
>   1 file changed, 5 deletions(-)
> 
> diff --git a/drivers/media/platform/amlogic/meson-ge2d/ge2d.c b/drivers/media/platform/amlogic/meson-ge2d/ge2d.c
> index 0c004bb8ba05..a9323b383547 100644
> --- a/drivers/media/platform/amlogic/meson-ge2d/ge2d.c
> +++ b/drivers/media/platform/amlogic/meson-ge2d/ge2d.c
> @@ -627,13 +627,8 @@ static int vidioc_s_fmt_cap(struct file *file, void *priv, struct v4l2_format *f
>   static int vidioc_g_fmt(struct file *file, void *priv, struct v4l2_format *f)
>   {
>   	struct ge2d_ctx *ctx = priv;
> -	struct vb2_queue *vq;
>   	struct ge2d_frame *frm;
>   
> -	vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, f->type);
> -	if (!vq)
> -		return -EINVAL;
> -
>   	frm = get_frame(ctx, f->type);
>   
>   	f->fmt.pix = frm->pix_fmt;

Reviewed-by: Neil Armstrong <neil.armstrong@linaro.org>

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: [PATCH 00/25] media: v4l2-mem2mem: Reduce cargo-cult
  2025-10-08 17:50 [PATCH 00/25] media: v4l2-mem2mem: Reduce cargo-cult Laurent Pinchart
                   ` (24 preceding siblings ...)
  2025-10-08 17:50 ` [PATCH 25/25] media: vim2m: " Laurent Pinchart
@ 2025-10-08 18:24 ` Nicolas Dufresne
  2025-10-08 19:21   ` Laurent Pinchart
  25 siblings, 1 reply; 42+ messages in thread
From: Nicolas Dufresne @ 2025-10-08 18:24 UTC (permalink / raw)
  To: Laurent Pinchart, linux-media, linux-mediatek, imx, linux-amlogic,
	linux-renesas-soc, linux-stm32, linux-rockchip, linux-arm-kernel,
	linux-arm-msm
  Cc: Matthew Majewski, Mirela Rabulea, Jacek Anaszewski,
	Michael Tretter, Devarsh Thakkar, Uwe Kleine-König,
	AngeloGioacchino Del Regno, Martin Blumenstingl, Alexandre Torgue,
	Philipp Zabel, Arnd Bergmann, Sylwester Nawrocki, Ming Qian,
	Pengutronix Kernel Team, Kieran Bingham, Nathan Chancellor,
	Sascha Hauer, Hans Verkuil, Mikhail Ulyanov, Kevin Hilman,
	Xavier Roumegue, Shuah Khan, Andrzej Pietrasiewicz, Tiffany Lin,
	Zhou Peng, Dikshita Agarwal, Vikash Garodia, Yunfei Dong,
	Ezequiel Garcia, Neil Armstrong, Jiasheng Jiang, Shawn Guo,
	Łukasz Stelmach, Abhinav Kumar, Heiko Stuebner,
	Benoit Parrot, Andrew-CT Chen, Geert Uytterhoeven, Magnus Damm,
	Sebastian Fricke, Maxime Coquelin, Jacob Chen, Bin Liu,
	Matthias Brugger, Fabio Estevam, Jerome Brunet,
	Bryan O'Donoghue

[-- Attachment #1: Type: text/plain, Size: 6036 bytes --]

Hi,

Le mercredi 08 octobre 2025 à 20:50 +0300, Laurent Pinchart a écrit :
> Hello,
> 
> The v4l2_m2m_get_vq() function never returns NULL, but many mem2mem
> drivers still check its return value and consider NULL as an error. This
> may have originated a long time ago from valid checks when
> v4l2_m2m_get_vq() could return NULL, with drivers then just copying the
> checks. This series attempts to stop the cargo-cult behaviour.
> 
> Patch 01/25 starts by explicitly stating in kerneldoc that the
> v4l2_m2m_get_vq() function never returns NULL. All the other patches
> drop NULL checks from drivers.
> 
> I have carefully checked all patched locations in all drivers. They fall
> in 3 categories:
> 
> - Checks in the VIDIOC_G_FMT, VIDIOC_TRY_FMT and VIDIOC_S_FMT handlers:
>   Those may have been added to ensure that the format type has a valid
>   value, but that is ensured by the V4L2 ioctl core before calling the
>   handlers. The checks can be dropped without a need to replace them
>   with proper type checks.
> 
> - Checks in the VIDIOC_S_SELECTION handler: The only location where this
>   is performed has an explicit type check, so the NULL check can also be
>   dropped.
> 
> - Checks in other locations where the type parameter to the
>   v4l2_m2m_get_vq() function is hardcoded: The hardcoded type is valid,
>   so the NULL check can't have been meant to check the type. It can also
>   be removed.
> 
> There's no dependency between any of those patches so they can be merged
> in any order.
> 
> Laurent Pinchart (25):
>   media: v4l2-mem2mem: Document that v4l2_m2m_get_vq() never returns
>     NULL
>   media: allgro-dvt: Drop unneeded v4l2_m2m_get_vq() NULL check
>   media: meson-g2d: Drop unneeded v4l2_m2m_get_vq() NULL check
>   media: amphion: Drop unneeded v4l2_m2m_get_vq() NULL check
>   media: coda: Drop unneeded v4l2_m2m_get_vq() NULL check
>   media: imagination: e5010: Drop unneeded v4l2_m2m_get_vq() NULL check
>   media: m2m-deinterlace: Drop unneeded v4l2_m2m_get_vq() NULL check
>   media: mediatek: jpeg: Drop unneeded v4l2_m2m_get_vq() NULL check
>   media: mediatek: vcodec: Drop unneeded v4l2_m2m_get_vq() NULL check
>   media: dw100: Drop unneeded v4l2_m2m_get_vq() NULL check
>   media: imx-jpeg: Drop unneeded v4l2_m2m_get_vq() NULL check
>   media: imx-pxp: Drop unneeded v4l2_m2m_get_vq() NULL check
>   media: nxp: imx8-isi: Drop unneeded v4l2_m2m_get_vq() NULL check
>   media: mx2_emmaprp: Drop unneeded v4l2_m2m_get_vq() NULL check
>   media: qcom: iris: Drop unneeded v4l2_m2m_get_vq() NULL check
>   media: qcom: venus: Drop unneeded v4l2_m2m_get_vq() NULL check
>   media: renesas: fdp1: Drop unneeded v4l2_m2m_get_vq() NULL check
>   media: rcar_jpu: Drop unneeded v4l2_m2m_get_vq() NULL check

Why not "renesas: jpu" to match the fdp1 patch naming ?

>   media: platform: rga: Drop unneeded v4l2_m2m_get_vq() NULL check
>   media: samsung: s5p-g2d: Drop unneeded v4l2_m2m_get_vq() NULL check
>   media: samsung: s5p-jpeg: Drop unneeded v4l2_m2m_get_vq() NULL check
>   media: stm32: dma2d: Drop unneeded v4l2_m2m_get_vq() NULL check
>   media: ti: vpe: Drop unneeded v4l2_m2m_get_vq() NULL check
>   media: vicodec: Drop unneeded v4l2_m2m_get_vq() NULL check
>   media: vim2m: Drop unneeded v4l2_m2m_get_vq() NULL check

I reviewed the list and it seems complete to me.

Nicolas

> 
>  drivers/media/platform/allegro-dvt/allegro-core.c    |  2 --
>  drivers/media/platform/amlogic/meson-ge2d/ge2d.c     |  5 -----
>  drivers/media/platform/amphion/vdec.c                |  2 --
>  drivers/media/platform/amphion/venc.c                |  2 --
>  .../media/platform/chips-media/coda/coda-common.c    |  4 ----
>  drivers/media/platform/imagination/e5010-jpeg-enc.c  |  4 ----
>  drivers/media/platform/m2m-deinterlace.c             |  7 -------
>  drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c |  7 -------
>  .../mediatek/vcodec/decoder/mtk_vcodec_dec.c         |  7 -------
>  .../vcodec/decoder/vdec/vdec_av1_req_lat_if.c        |  2 --
>  .../vcodec/decoder/vdec/vdec_vp9_req_lat_if.c        |  2 --
>  .../mediatek/vcodec/encoder/mtk_vcodec_enc.c         |  8 --------
>  drivers/media/platform/nxp/dw100/dw100.c             |  7 -------
>  drivers/media/platform/nxp/imx-jpeg/mxc-jpeg.c       |  4 ----
>  drivers/media/platform/nxp/imx-pxp.c                 |  7 -------
>  drivers/media/platform/nxp/imx8-isi/imx8-isi-m2m.c   |  2 --
>  drivers/media/platform/nxp/mx2_emmaprp.c             |  7 -------
>  drivers/media/platform/qcom/iris/iris_vdec.c         |  2 --
>  drivers/media/platform/qcom/venus/vdec.c             |  2 --
>  drivers/media/platform/qcom/venus/venc.c             |  2 --
>  drivers/media/platform/renesas/rcar_fdp1.c           |  3 ---
>  drivers/media/platform/renesas/rcar_jpu.c            |  8 --------
>  drivers/media/platform/rockchip/rga/rga.c            |  4 ----
>  drivers/media/platform/samsung/s5p-g2d/g2d.c         |  4 ----
>  drivers/media/platform/samsung/s5p-jpeg/jpeg-core.c  |  7 -------
>  drivers/media/platform/st/stm32/dma2d/dma2d.c        |  5 -----
>  drivers/media/platform/ti/vpe/vpe.c                  |  7 -------
>  drivers/media/test-drivers/vicodec/vicodec-core.c    |  7 -------
>  drivers/media/test-drivers/vim2m.c                   | 12 ------------
>  drivers/media/v4l2-core/v4l2-mem2mem.c               | 12 +-----------
>  include/media/v4l2-mem2mem.h                         |  3 +++
>  31 files changed, 4 insertions(+), 153 deletions(-)
> 
> 
> base-commit: e5f0a698b34ed76002dc5cff3804a61c80233a7a

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: [PATCH 00/25] media: v4l2-mem2mem: Reduce cargo-cult
  2025-10-08 18:24 ` [PATCH 00/25] media: v4l2-mem2mem: Reduce cargo-cult Nicolas Dufresne
@ 2025-10-08 19:21   ` Laurent Pinchart
  0 siblings, 0 replies; 42+ messages in thread
From: Laurent Pinchart @ 2025-10-08 19:21 UTC (permalink / raw)
  To: Nicolas Dufresne
  Cc: linux-media, linux-mediatek, imx, linux-amlogic,
	linux-renesas-soc, linux-stm32, linux-rockchip, linux-arm-kernel,
	linux-arm-msm, Matthew Majewski, Mirela Rabulea, Jacek Anaszewski,
	Michael Tretter, Devarsh Thakkar, Uwe Kleine-König,
	AngeloGioacchino Del Regno, Martin Blumenstingl, Alexandre Torgue,
	Philipp Zabel, Arnd Bergmann, Sylwester Nawrocki, Ming Qian,
	Pengutronix Kernel Team, Kieran Bingham, Nathan Chancellor,
	Sascha Hauer, Hans Verkuil, Kevin Hilman, Xavier Roumegue,
	Shuah Khan, Andrzej Pietrasiewicz, Tiffany Lin, Zhou Peng,
	Dikshita Agarwal, Vikash Garodia, Yunfei Dong, Ezequiel Garcia,
	Neil Armstrong, Jiasheng Jiang, Shawn Guo, Łukasz Stelmach,
	Abhinav Kumar, Heiko Stuebner, Benoit Parrot, Andrew-CT Chen,
	Geert Uytterhoeven, Magnus Damm, Maxime Coquelin, Jacob Chen,
	Bin Liu, Matthias Brugger, Fabio Estevam, Jerome Brunet,
	Bryan O'Donoghue

On Wed, Oct 08, 2025 at 02:24:30PM -0400, Nicolas Dufresne wrote:
> Hi,
> 
> Le mercredi 08 octobre 2025 à 20:50 +0300, Laurent Pinchart a écrit :
> > Hello,
> > 
> > The v4l2_m2m_get_vq() function never returns NULL, but many mem2mem
> > drivers still check its return value and consider NULL as an error. This
> > may have originated a long time ago from valid checks when
> > v4l2_m2m_get_vq() could return NULL, with drivers then just copying the
> > checks. This series attempts to stop the cargo-cult behaviour.
> > 
> > Patch 01/25 starts by explicitly stating in kerneldoc that the
> > v4l2_m2m_get_vq() function never returns NULL. All the other patches
> > drop NULL checks from drivers.
> > 
> > I have carefully checked all patched locations in all drivers. They fall
> > in 3 categories:
> > 
> > - Checks in the VIDIOC_G_FMT, VIDIOC_TRY_FMT and VIDIOC_S_FMT handlers:
> >   Those may have been added to ensure that the format type has a valid
> >   value, but that is ensured by the V4L2 ioctl core before calling the
> >   handlers. The checks can be dropped without a need to replace them
> >   with proper type checks.
> > 
> > - Checks in the VIDIOC_S_SELECTION handler: The only location where this
> >   is performed has an explicit type check, so the NULL check can also be
> >   dropped.
> > 
> > - Checks in other locations where the type parameter to the
> >   v4l2_m2m_get_vq() function is hardcoded: The hardcoded type is valid,
> >   so the NULL check can't have been meant to check the type. It can also
> >   be removed.
> > 
> > There's no dependency between any of those patches so they can be merged
> > in any order.
> > 
> > Laurent Pinchart (25):
> >   media: v4l2-mem2mem: Document that v4l2_m2m_get_vq() never returns
> >     NULL
> >   media: allgro-dvt: Drop unneeded v4l2_m2m_get_vq() NULL check
> >   media: meson-g2d: Drop unneeded v4l2_m2m_get_vq() NULL check
> >   media: amphion: Drop unneeded v4l2_m2m_get_vq() NULL check
> >   media: coda: Drop unneeded v4l2_m2m_get_vq() NULL check
> >   media: imagination: e5010: Drop unneeded v4l2_m2m_get_vq() NULL check
> >   media: m2m-deinterlace: Drop unneeded v4l2_m2m_get_vq() NULL check
> >   media: mediatek: jpeg: Drop unneeded v4l2_m2m_get_vq() NULL check
> >   media: mediatek: vcodec: Drop unneeded v4l2_m2m_get_vq() NULL check
> >   media: dw100: Drop unneeded v4l2_m2m_get_vq() NULL check
> >   media: imx-jpeg: Drop unneeded v4l2_m2m_get_vq() NULL check
> >   media: imx-pxp: Drop unneeded v4l2_m2m_get_vq() NULL check
> >   media: nxp: imx8-isi: Drop unneeded v4l2_m2m_get_vq() NULL check
> >   media: mx2_emmaprp: Drop unneeded v4l2_m2m_get_vq() NULL check
> >   media: qcom: iris: Drop unneeded v4l2_m2m_get_vq() NULL check
> >   media: qcom: venus: Drop unneeded v4l2_m2m_get_vq() NULL check
> >   media: renesas: fdp1: Drop unneeded v4l2_m2m_get_vq() NULL check
> >   media: rcar_jpu: Drop unneeded v4l2_m2m_get_vq() NULL check
> 
> Why not "renesas: jpu" to match the fdp1 patch naming ?

I tried to go with the most common prefix as reported by git log. I
don't mind changing this, I'll wait for more reviews to see if a v2 is
needed, otherwise this can be updated when applying if desired.

> >   media: platform: rga: Drop unneeded v4l2_m2m_get_vq() NULL check
> >   media: samsung: s5p-g2d: Drop unneeded v4l2_m2m_get_vq() NULL check
> >   media: samsung: s5p-jpeg: Drop unneeded v4l2_m2m_get_vq() NULL check
> >   media: stm32: dma2d: Drop unneeded v4l2_m2m_get_vq() NULL check
> >   media: ti: vpe: Drop unneeded v4l2_m2m_get_vq() NULL check
> >   media: vicodec: Drop unneeded v4l2_m2m_get_vq() NULL check
> >   media: vim2m: Drop unneeded v4l2_m2m_get_vq() NULL check
> 
> I reviewed the list and it seems complete to me.

Thank you.

> >  drivers/media/platform/allegro-dvt/allegro-core.c    |  2 --
> >  drivers/media/platform/amlogic/meson-ge2d/ge2d.c     |  5 -----
> >  drivers/media/platform/amphion/vdec.c                |  2 --
> >  drivers/media/platform/amphion/venc.c                |  2 --
> >  .../media/platform/chips-media/coda/coda-common.c    |  4 ----
> >  drivers/media/platform/imagination/e5010-jpeg-enc.c  |  4 ----
> >  drivers/media/platform/m2m-deinterlace.c             |  7 -------
> >  drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c |  7 -------
> >  .../mediatek/vcodec/decoder/mtk_vcodec_dec.c         |  7 -------
> >  .../vcodec/decoder/vdec/vdec_av1_req_lat_if.c        |  2 --
> >  .../vcodec/decoder/vdec/vdec_vp9_req_lat_if.c        |  2 --
> >  .../mediatek/vcodec/encoder/mtk_vcodec_enc.c         |  8 --------
> >  drivers/media/platform/nxp/dw100/dw100.c             |  7 -------
> >  drivers/media/platform/nxp/imx-jpeg/mxc-jpeg.c       |  4 ----
> >  drivers/media/platform/nxp/imx-pxp.c                 |  7 -------
> >  drivers/media/platform/nxp/imx8-isi/imx8-isi-m2m.c   |  2 --
> >  drivers/media/platform/nxp/mx2_emmaprp.c             |  7 -------
> >  drivers/media/platform/qcom/iris/iris_vdec.c         |  2 --
> >  drivers/media/platform/qcom/venus/vdec.c             |  2 --
> >  drivers/media/platform/qcom/venus/venc.c             |  2 --
> >  drivers/media/platform/renesas/rcar_fdp1.c           |  3 ---
> >  drivers/media/platform/renesas/rcar_jpu.c            |  8 --------
> >  drivers/media/platform/rockchip/rga/rga.c            |  4 ----
> >  drivers/media/platform/samsung/s5p-g2d/g2d.c         |  4 ----
> >  drivers/media/platform/samsung/s5p-jpeg/jpeg-core.c  |  7 -------
> >  drivers/media/platform/st/stm32/dma2d/dma2d.c        |  5 -----
> >  drivers/media/platform/ti/vpe/vpe.c                  |  7 -------
> >  drivers/media/test-drivers/vicodec/vicodec-core.c    |  7 -------
> >  drivers/media/test-drivers/vim2m.c                   | 12 ------------
> >  drivers/media/v4l2-core/v4l2-mem2mem.c               | 12 +-----------
> >  include/media/v4l2-mem2mem.h                         |  3 +++
> >  31 files changed, 4 insertions(+), 153 deletions(-)
> > 
> > 
> > base-commit: e5f0a698b34ed76002dc5cff3804a61c80233a7a

-- 
Regards,

Laurent Pinchart

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: [PATCH 11/25] media: imx-jpeg: Drop unneeded v4l2_m2m_get_vq() NULL check
  2025-10-08 17:50 ` [PATCH 11/25] media: imx-jpeg: " Laurent Pinchart
@ 2025-10-08 20:01   ` Frank Li
  0 siblings, 0 replies; 42+ messages in thread
From: Frank Li @ 2025-10-08 20:01 UTC (permalink / raw)
  To: Laurent Pinchart
  Cc: linux-media, imx, linux-arm-kernel, Nicolas Dufresne,
	Mirela Rabulea, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team,
	Fabio Estevam

On Wed, Oct 08, 2025 at 08:50:38PM +0300, Laurent Pinchart wrote:
> The v4l2_m2m_get_vq() function never returns NULL. The check may have
> been intended to catch invalid format types, but that's not needed as
> the V4L2 core picks the appropriate VIDIOC_S_FMT ioctl handler based on
> the format type, so the type can't be incorrect. Drop the unneeded
> return value check.
>
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

Reviewed-by: Frank Li <Frank.Li@nxp.com>

> ---
>  drivers/media/platform/nxp/imx-jpeg/mxc-jpeg.c | 4 ----
>  1 file changed, 4 deletions(-)
>
> diff --git a/drivers/media/platform/nxp/imx-jpeg/mxc-jpeg.c b/drivers/media/platform/nxp/imx-jpeg/mxc-jpeg.c
> index 8681dd193033..37e0670f98c5 100644
> --- a/drivers/media/platform/nxp/imx-jpeg/mxc-jpeg.c
> +++ b/drivers/media/platform/nxp/imx-jpeg/mxc-jpeg.c
> @@ -2492,8 +2492,6 @@ static int mxc_jpeg_s_fmt(struct mxc_jpeg_ctx *ctx,
>  	struct mxc_jpeg_dev *jpeg = ctx->mxc_jpeg;
>
>  	vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, f->type);
> -	if (!vq)
> -		return -EINVAL;
>
>  	if (vb2_is_busy(vq)) {
>  		v4l2_err(&jpeg->v4l2_dev, "queue busy\n");
> @@ -2529,8 +2527,6 @@ static int mxc_jpeg_s_fmt_vid_out(struct file *file, void *priv,
>  		return 0;
>
>  	dst_vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, cap_type);
> -	if (!dst_vq)
> -		return -EINVAL;
>
>  	if (vb2_is_busy(dst_vq))
>  		return 0;
> --
> Regards,
>
> Laurent Pinchart
>

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: [PATCH 12/25] media: imx-pxp: Drop unneeded v4l2_m2m_get_vq() NULL check
  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
  1 sibling, 0 replies; 42+ messages in thread
From: Frank Li @ 2025-10-08 20:02 UTC (permalink / raw)
  To: Laurent Pinchart
  Cc: linux-media, imx, linux-arm-kernel, Nicolas Dufresne,
	Philipp Zabel, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team,
	Fabio Estevam

On Wed, Oct 08, 2025 at 08:50:39PM +0300, Laurent Pinchart wrote:
> The v4l2_m2m_get_vq() function never returns NULL.
>
> In the set format handler, the check may have been intended to catch
> invalid format types, but that's not needed as the V4L2 core picks the
> appropriate VIDIOC_S_FMT ioctl handler based on the format type, so the
> type can't be incorrect.
>
> In the get format handler, the return value is not used for any purpose
> other than the NULL check, which was therefore probably intended to
> catch invalid format types. That's not needed for the same reason as in
> the set format handler.
>
> Drop the unneeded return value checks and, as the function has no side
> effect, the unneeded function call as well.
>
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> ---

Reviewed-by: Frank Li <Frank.Li@nxp.com>

>  drivers/media/platform/nxp/imx-pxp.c | 7 -------
>  1 file changed, 7 deletions(-)
>
> diff --git a/drivers/media/platform/nxp/imx-pxp.c b/drivers/media/platform/nxp/imx-pxp.c
> index 7f8ffbac582f..5386650ce194 100644
> --- a/drivers/media/platform/nxp/imx-pxp.c
> +++ b/drivers/media/platform/nxp/imx-pxp.c
> @@ -1180,13 +1180,8 @@ static int pxp_enum_fmt_vid_out(struct file *file, void *priv,
>
>  static int pxp_g_fmt(struct pxp_ctx *ctx, struct v4l2_format *f)
>  {
> -	struct vb2_queue *vq;
>  	struct pxp_q_data *q_data;
>
> -	vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, f->type);
> -	if (!vq)
> -		return -EINVAL;
> -
>  	q_data = get_q_data(ctx, f->type);
>
>  	f->fmt.pix.width	= q_data->width;
> @@ -1329,8 +1324,6 @@ static int pxp_s_fmt(struct pxp_ctx *ctx, struct v4l2_format *f)
>  	struct vb2_queue *vq;
>
>  	vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, f->type);
> -	if (!vq)
> -		return -EINVAL;
>
>  	q_data = get_q_data(ctx, f->type);
>  	if (!q_data)
> --
> Regards,
>
> Laurent Pinchart
>

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: [PATCH 13/25] media: nxp: imx8-isi: Drop unneeded v4l2_m2m_get_vq() NULL check
  2025-10-08 17:50 ` [PATCH 13/25] media: nxp: imx8-isi: " Laurent Pinchart
@ 2025-10-08 20:02   ` Frank Li
  0 siblings, 0 replies; 42+ messages in thread
From: Frank Li @ 2025-10-08 20:02 UTC (permalink / raw)
  To: Laurent Pinchart
  Cc: linux-media, imx, linux-arm-kernel, Nicolas Dufresne, Shawn Guo,
	Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam

On Wed, Oct 08, 2025 at 08:50:40PM +0300, Laurent Pinchart wrote:
> The v4l2_m2m_get_vq() function never returns NULL. The check may have
> been intended to catch invalid format types, but that's not needed as
> the V4L2 core picks the appropriate VIDIOC_S_FMT ioctl handler based on
> the format type, so the type can't be incorrect. Drop the unneeded
> return value check.
>
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> ---

Reviewed-by: Frank Li <Frank.Li@nxp.com>

>  drivers/media/platform/nxp/imx8-isi/imx8-isi-m2m.c | 2 --
>  1 file changed, 2 deletions(-)
>
> diff --git a/drivers/media/platform/nxp/imx8-isi/imx8-isi-m2m.c b/drivers/media/platform/nxp/imx8-isi/imx8-isi-m2m.c
> index 6822c2f7fc69..675f1d2b65d9 100644
> --- a/drivers/media/platform/nxp/imx8-isi/imx8-isi-m2m.c
> +++ b/drivers/media/platform/nxp/imx8-isi/imx8-isi-m2m.c
> @@ -554,8 +554,6 @@ static int mxc_isi_m2m_s_fmt_vid(struct file *file, void *fh,
>  	struct vb2_queue *vq;
>
>  	vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, f->type);
> -	if (!vq)
> -		return -EINVAL;
>
>  	if (vb2_is_busy(vq))
>  		return -EBUSY;
> --
> Regards,
>
> Laurent Pinchart
>

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: [PATCH 15/25] media: qcom: iris: Drop unneeded v4l2_m2m_get_vq() NULL check
  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
  1 sibling, 0 replies; 42+ messages in thread
From: Bryan O'Donoghue @ 2025-10-08 23:51 UTC (permalink / raw)
  To: Laurent Pinchart, linux-media, linux-arm-msm
  Cc: Nicolas Dufresne, Vikash Garodia, Dikshita Agarwal, Abhinav Kumar

On 08/10/2025 18:50, Laurent Pinchart wrote:
> The v4l2_m2m_get_vq() function never returns NULL. The check may have
> been intended to catch invalid format types, but that's not needed as
> the V4L2 core picks the appropriate VIDIOC_S_FMT ioctl handler based on
> the format type, so the type can't be incorrect. Drop the unneeded
> return value check.
> 
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> ---
>   drivers/media/platform/qcom/iris/iris_vdec.c | 2 --
>   1 file changed, 2 deletions(-)
> 
> diff --git a/drivers/media/platform/qcom/iris/iris_vdec.c b/drivers/media/platform/qcom/iris/iris_vdec.c
> index d670b51c5839..1e9ffdbb6e18 100644
> --- a/drivers/media/platform/qcom/iris/iris_vdec.c
> +++ b/drivers/media/platform/qcom/iris/iris_vdec.c
> @@ -191,8 +191,6 @@ int iris_vdec_s_fmt(struct iris_inst *inst, struct v4l2_format *f)
>   	u32 codec_align;
>   
>   	q = v4l2_m2m_get_vq(inst->m2m_ctx, f->type);
> -	if (!q)
> -		return -EINVAL;
>   
>   	if (vb2_is_busy(q))
>   		return -EBUSY;
Reviewed-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: [PATCH 16/25] media: qcom: venus: Drop unneeded v4l2_m2m_get_vq() NULL check
  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
  1 sibling, 0 replies; 42+ messages in thread
From: Bryan O'Donoghue @ 2025-10-08 23:52 UTC (permalink / raw)
  To: Laurent Pinchart, linux-media, linux-arm-msm
  Cc: Nicolas Dufresne, Vikash Garodia, Dikshita Agarwal

On 08/10/2025 18:50, Laurent Pinchart wrote:
> The v4l2_m2m_get_vq() function never returns NULL. The check may have
> been intended to catch invalid format types, but that's not needed as
> the V4L2 core picks the appropriate VIDIOC_S_FMT ioctl handler based on
> the format type, so the type can't be incorrect. Drop the unneeded
> return value check.
> 
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> ---
>   drivers/media/platform/qcom/venus/vdec.c | 2 --
>   drivers/media/platform/qcom/venus/venc.c | 2 --
>   2 files changed, 4 deletions(-)
> 
> diff --git a/drivers/media/platform/qcom/venus/vdec.c b/drivers/media/platform/qcom/venus/vdec.c
> index 29b0d6a5303d..8c77db0f6e76 100644
> --- a/drivers/media/platform/qcom/venus/vdec.c
> +++ b/drivers/media/platform/qcom/venus/vdec.c
> @@ -329,8 +329,6 @@ static int vdec_s_fmt(struct file *file, void *fh, struct v4l2_format *f)
>   	struct vb2_queue *q;
>   
>   	q = v4l2_m2m_get_vq(inst->m2m_ctx, f->type);
> -	if (!q)
> -		return -EINVAL;
>   
>   	if (vb2_is_busy(q))
>   		return -EBUSY;
> diff --git a/drivers/media/platform/qcom/venus/venc.c b/drivers/media/platform/qcom/venus/venc.c
> index c0a0ccdded80..0fe4cc37118b 100644
> --- a/drivers/media/platform/qcom/venus/venc.c
> +++ b/drivers/media/platform/qcom/venus/venc.c
> @@ -241,8 +241,6 @@ static int venc_s_fmt(struct file *file, void *fh, struct v4l2_format *f)
>   	struct vb2_queue *q;
>   
>   	q = v4l2_m2m_get_vq(inst->m2m_ctx, f->type);
> -	if (!q)
> -		return -EINVAL;
>   
>   	if (vb2_is_busy(q))
>   		return -EBUSY;
Reviewed-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: [PATCH 16/25] media: qcom: venus: Drop unneeded v4l2_m2m_get_vq() NULL check
  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
  1 sibling, 0 replies; 42+ messages in thread
From: Dikshita Agarwal @ 2025-10-09  7:42 UTC (permalink / raw)
  To: Laurent Pinchart, linux-media, linux-arm-msm
  Cc: Nicolas Dufresne, Vikash Garodia, Bryan O'Donoghue



On 10/8/2025 11:20 PM, Laurent Pinchart wrote:
> The v4l2_m2m_get_vq() function never returns NULL. The check may have
> been intended to catch invalid format types, but that's not needed as
> the V4L2 core picks the appropriate VIDIOC_S_FMT ioctl handler based on
> the format type, so the type can't be incorrect. Drop the unneeded
> return value check.
> 
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> ---
>  drivers/media/platform/qcom/venus/vdec.c | 2 --
>  drivers/media/platform/qcom/venus/venc.c | 2 --
>  2 files changed, 4 deletions(-)
> 
> diff --git a/drivers/media/platform/qcom/venus/vdec.c b/drivers/media/platform/qcom/venus/vdec.c
> index 29b0d6a5303d..8c77db0f6e76 100644
> --- a/drivers/media/platform/qcom/venus/vdec.c
> +++ b/drivers/media/platform/qcom/venus/vdec.c
> @@ -329,8 +329,6 @@ static int vdec_s_fmt(struct file *file, void *fh, struct v4l2_format *f)
>  	struct vb2_queue *q;
>  
>  	q = v4l2_m2m_get_vq(inst->m2m_ctx, f->type);
> -	if (!q)
> -		return -EINVAL;
>  
>  	if (vb2_is_busy(q))
>  		return -EBUSY;
> diff --git a/drivers/media/platform/qcom/venus/venc.c b/drivers/media/platform/qcom/venus/venc.c
> index c0a0ccdded80..0fe4cc37118b 100644
> --- a/drivers/media/platform/qcom/venus/venc.c
> +++ b/drivers/media/platform/qcom/venus/venc.c
> @@ -241,8 +241,6 @@ static int venc_s_fmt(struct file *file, void *fh, struct v4l2_format *f)
>  	struct vb2_queue *q;
>  
>  	q = v4l2_m2m_get_vq(inst->m2m_ctx, f->type);
> -	if (!q)
> -		return -EINVAL;
>  
>  	if (vb2_is_busy(q))
>  		return -EBUSY;

Reviewed-by: Dikshita Agarwal <dikshita.agarwal@oss.qualcomm.com>

Thanks,
Dikshita

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: [PATCH 05/25] media: coda: Drop unneeded v4l2_m2m_get_vq() NULL check
  2025-10-08 17:50 ` [PATCH 05/25] media: coda: " Laurent Pinchart
@ 2025-10-09  8:11   ` Philipp Zabel
  0 siblings, 0 replies; 42+ messages in thread
From: Philipp Zabel @ 2025-10-09  8:11 UTC (permalink / raw)
  To: Laurent Pinchart, linux-media; +Cc: Nicolas Dufresne

On Mi, 2025-10-08 at 20:50 +0300, Laurent Pinchart wrote:
> The v4l2_m2m_get_vq() function never returns NULL. The check may have
> been intended to catch invalid format types, but that's not needed as
> the V4L2 core picks the appropriate VIDIOC_S_FMT ioctl handler based on
> the format type, so the type can't be incorrect. Drop the unneeded
> return value check.
> 
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> ---
>  drivers/media/platform/chips-media/coda/coda-common.c | 4 ----
>  1 file changed, 4 deletions(-)
> 
> diff --git a/drivers/media/platform/chips-media/coda/coda-common.c b/drivers/media/platform/chips-media/coda/coda-common.c
> index e6e3f5ec24f6..5451b01e0815 100644
> --- a/drivers/media/platform/chips-media/coda/coda-common.c
> +++ b/drivers/media/platform/chips-media/coda/coda-common.c
> @@ -785,8 +785,6 @@ static int coda_s_fmt(struct coda_ctx *ctx, struct v4l2_format *f,
>  	struct vb2_queue *vq;
>  
>  	vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, f->type);
> -	if (!vq)
> -		return -EINVAL;
>  
>  	q_data = get_q_data(ctx, f->type);
>  	if (!q_data)
> @@ -937,8 +935,6 @@ static int coda_s_fmt_vid_out(struct file *file, void *priv,
>  	ctx->codec = codec;
>  
>  	dst_vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE);
> -	if (!dst_vq)
> -		return -EINVAL;
>  
>  	/*
>  	 * Setting the capture queue format is not possible while the capture

Reviewed-by: Philipp Zabel <p.zabel@pengutronix.de>

regards
Philipp

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: [PATCH 12/25] media: imx-pxp: Drop unneeded v4l2_m2m_get_vq() NULL check
  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
  1 sibling, 0 replies; 42+ messages in thread
From: Philipp Zabel @ 2025-10-09  8:11 UTC (permalink / raw)
  To: Laurent Pinchart, linux-media, imx, linux-arm-kernel
  Cc: Nicolas Dufresne, Shawn Guo, Sascha Hauer,
	Pengutronix Kernel Team, Fabio Estevam

On Mi, 2025-10-08 at 20:50 +0300, Laurent Pinchart wrote:
> The v4l2_m2m_get_vq() function never returns NULL.
> 
> In the set format handler, the check may have been intended to catch
> invalid format types, but that's not needed as the V4L2 core picks the
> appropriate VIDIOC_S_FMT ioctl handler based on the format type, so the
> type can't be incorrect.
> 
> In the get format handler, the return value is not used for any purpose
> other than the NULL check, which was therefore probably intended to
> catch invalid format types. That's not needed for the same reason as in
> the set format handler.
> 
> Drop the unneeded return value checks and, as the function has no side
> effect, the unneeded function call as well.
> 
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> ---
>  drivers/media/platform/nxp/imx-pxp.c | 7 -------
>  1 file changed, 7 deletions(-)
> 
> diff --git a/drivers/media/platform/nxp/imx-pxp.c b/drivers/media/platform/nxp/imx-pxp.c
> index 7f8ffbac582f..5386650ce194 100644
> --- a/drivers/media/platform/nxp/imx-pxp.c
> +++ b/drivers/media/platform/nxp/imx-pxp.c
> @@ -1180,13 +1180,8 @@ static int pxp_enum_fmt_vid_out(struct file *file, void *priv,
>  
>  static int pxp_g_fmt(struct pxp_ctx *ctx, struct v4l2_format *f)
>  {
> -	struct vb2_queue *vq;
>  	struct pxp_q_data *q_data;
>  
> -	vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, f->type);
> -	if (!vq)
> -		return -EINVAL;
> -
>  	q_data = get_q_data(ctx, f->type);
>  
>  	f->fmt.pix.width	= q_data->width;
> @@ -1329,8 +1324,6 @@ static int pxp_s_fmt(struct pxp_ctx *ctx, struct v4l2_format *f)
>  	struct vb2_queue *vq;
>  
>  	vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, f->type);
> -	if (!vq)
> -		return -EINVAL;
>  
>  	q_data = get_q_data(ctx, f->type);
>  	if (!q_data)


Reviewed-by: Philipp Zabel <p.zabel@pengutronix.de>

regards
Philipp

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: [PATCH 15/25] media: qcom: iris: Drop unneeded v4l2_m2m_get_vq() NULL check
  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
  1 sibling, 1 reply; 42+ messages in thread
From: Dikshita Agarwal @ 2025-10-09 13:53 UTC (permalink / raw)
  To: Laurent Pinchart, linux-media, linux-arm-msm
  Cc: Nicolas Dufresne, Vikash Garodia, Abhinav Kumar,
	Bryan O'Donoghue



On 10/8/2025 11:20 PM, Laurent Pinchart wrote:
> The v4l2_m2m_get_vq() function never returns NULL. The check may have
> been intended to catch invalid format types, but that's not needed as
> the V4L2 core picks the appropriate VIDIOC_S_FMT ioctl handler based on
> the format type, so the type can't be incorrect. Drop the unneeded
> return value check.
> 
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> ---
>  drivers/media/platform/qcom/iris/iris_vdec.c | 2 --
>  1 file changed, 2 deletions(-)
> 
> diff --git a/drivers/media/platform/qcom/iris/iris_vdec.c b/drivers/media/platform/qcom/iris/iris_vdec.c
> index d670b51c5839..1e9ffdbb6e18 100644
> --- a/drivers/media/platform/qcom/iris/iris_vdec.c
> +++ b/drivers/media/platform/qcom/iris/iris_vdec.c
> @@ -191,8 +191,6 @@ int iris_vdec_s_fmt(struct iris_inst *inst, struct v4l2_format *f)
>  	u32 codec_align;
>  
>  	q = v4l2_m2m_get_vq(inst->m2m_ctx, f->type);
> -	if (!q)
> -		return -EINVAL;
>  
>  	if (vb2_is_busy(q))
>  		return -EBUSY;

The same change would be required for iris_venc.c as well which is part of
linux-next[1]

[1]:
https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/tree/drivers/media/platform/qcom/iris/iris_venc.c#n271

Thanks,
Dikshita




^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: [PATCH 01/25] media: v4l2-mem2mem: Document that v4l2_m2m_get_vq() never returns NULL
  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
  0 siblings, 0 replies; 42+ messages in thread
From: Stefan Klug @ 2025-10-10  8:35 UTC (permalink / raw)
  To: Laurent Pinchart, linux-media; +Cc: Nicolas Dufresne

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
> 
>

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: [PATCH 10/25] media: dw100: Drop unneeded v4l2_m2m_get_vq() NULL check
  2025-10-08 17:50 ` [PATCH 10/25] media: dw100: " Laurent Pinchart
@ 2025-10-10  8:40   ` Stefan Klug
  0 siblings, 0 replies; 42+ messages in thread
From: Stefan Klug @ 2025-10-10  8:40 UTC (permalink / raw)
  To: Laurent Pinchart, linux-media; +Cc: Nicolas Dufresne, Xavier Roumegue

Hi Laurent,

Thank you for the patch.

Quoting Laurent Pinchart (2025-10-08 19:50:37)
> The v4l2_m2m_get_vq() function never returns NULL.
> 
> In the set format handler, the check may have been intended to catch
> invalid format types, but that's not needed as the V4L2 core picks the
> appropriate VIDIOC_S_FMT ioctl handler based on the format type, so the
> type can't be incorrect.
> 
> In the get format handler, the return value is not used for any purpose
> other than the NULL check, which was therefore probably intended to
> catch invalid format types. That's not needed for the same reason as in
> the set format handler.
> 
> Drop the unneeded return value checks and, as the function has no side
> effect, the unneeded function call as well.
> 
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

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

Cheers,
Stefan

> ---
>  drivers/media/platform/nxp/dw100/dw100.c | 7 -------
>  1 file changed, 7 deletions(-)
> 
> diff --git a/drivers/media/platform/nxp/dw100/dw100.c b/drivers/media/platform/nxp/dw100/dw100.c
> index fed1788d0702..7a0ee44d9e1f 100644
> --- a/drivers/media/platform/nxp/dw100/dw100.c
> +++ b/drivers/media/platform/nxp/dw100/dw100.c
> @@ -765,13 +765,8 @@ static int dw100_enum_framesizes(struct file *file, void *priv,
>  static int dw100_g_fmt_vid(struct file *file, void *priv, struct v4l2_format *f)
>  {
>         struct dw100_ctx *ctx = dw100_file2ctx(file);
> -       struct vb2_queue *vq;
>         struct dw100_q_data *q_data;
>  
> -       vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, f->type);
> -       if (!vq)
> -               return -EINVAL;
> -
>         q_data = dw100_get_q_data(ctx, f->type);
>  
>         f->fmt.pix_mp = q_data->pix_fmt;
> @@ -833,8 +828,6 @@ static int dw100_s_fmt(struct dw100_ctx *ctx, struct v4l2_format *f)
>         struct vb2_queue *vq;
>  
>         vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, f->type);
> -       if (!vq)
> -               return -EINVAL;
>  
>         q_data = dw100_get_q_data(ctx, f->type);
>         if (!q_data)
> -- 
> Regards,
> 
> Laurent Pinchart
> 
>

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: [PATCH 20/25] media: samsung: s5p-g2d: Drop unneeded v4l2_m2m_get_vq() NULL check
  2025-10-08 17:50 ` [PATCH 20/25] media: samsung: s5p-g2d: " Laurent Pinchart
@ 2025-10-10 11:00   ` Lukasz Stelmach
  0 siblings, 0 replies; 42+ messages in thread
From: Lukasz Stelmach @ 2025-10-10 11:00 UTC (permalink / raw)
  To: Laurent Pinchart
  Cc: linux-media, linux-arm-kernel, Nicolas Dufresne, Marek Szyprowski

[-- Attachment #1: Type: text/plain, Size: 1527 bytes --]

It was <2025-10-08 śro 20:50>, when Laurent Pinchart wrote:
> The v4l2_m2m_get_vq() function never returns NULL. The check was
> probably intended to catch invalid format types, but that's not needed
> as the V4L2 core picks the appropriate VIDIOC_G_FMT ioctl handler based
> on the format type, so the type can't be incorrect. Drop the unneeded
> return value check and, as the return value is not used for other
> purposes and the function has no side effect, the function call as well.
>
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> ---
>  drivers/media/platform/samsung/s5p-g2d/g2d.c | 4 ----
>  1 file changed, 4 deletions(-)
>

Reviewed-by: Łukasz Stelmach <l.stelmach@samsung.com>

> diff --git a/drivers/media/platform/samsung/s5p-g2d/g2d.c b/drivers/media/platform/samsung/s5p-g2d/g2d.c
> index ffed16a34493..7b0481c7f953 100644
> --- a/drivers/media/platform/samsung/s5p-g2d/g2d.c
> +++ b/drivers/media/platform/samsung/s5p-g2d/g2d.c
> @@ -306,12 +306,8 @@ static int vidioc_enum_fmt(struct file *file, void *prv, struct v4l2_fmtdesc *f)
>  static int vidioc_g_fmt(struct file *file, void *prv, struct v4l2_format *f)
>  {
>  	struct g2d_ctx *ctx = prv;
> -	struct vb2_queue *vq;
>  	struct g2d_frame *frm;
>  
> -	vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, f->type);
> -	if (!vq)
> -		return -EINVAL;
>  	frm = get_frame(ctx, f->type);
>  	if (IS_ERR(frm))
>  		return PTR_ERR(frm);

-- 
Łukasz Stelmach
Samsung R&D Institute Poland
Samsung Electronics

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 487 bytes --]

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: [PATCH 15/25] media: qcom: iris: Drop unneeded v4l2_m2m_get_vq() NULL check
  2025-10-09 13:53   ` Dikshita Agarwal
@ 2025-10-10 11:14     ` Laurent Pinchart
  0 siblings, 0 replies; 42+ messages in thread
From: Laurent Pinchart @ 2025-10-10 11:14 UTC (permalink / raw)
  To: Dikshita Agarwal
  Cc: linux-media, linux-arm-msm, Nicolas Dufresne, Vikash Garodia,
	Abhinav Kumar, Bryan O'Donoghue

Hi Dikshita,

On Thu, Oct 09, 2025 at 07:23:20PM +0530, Dikshita Agarwal wrote:
> On 10/8/2025 11:20 PM, Laurent Pinchart wrote:
> > The v4l2_m2m_get_vq() function never returns NULL. The check may have
> > been intended to catch invalid format types, but that's not needed as
> > the V4L2 core picks the appropriate VIDIOC_S_FMT ioctl handler based on
> > the format type, so the type can't be incorrect. Drop the unneeded
> > return value check.
> > 
> > Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> > ---
> >  drivers/media/platform/qcom/iris/iris_vdec.c | 2 --
> >  1 file changed, 2 deletions(-)
> > 
> > diff --git a/drivers/media/platform/qcom/iris/iris_vdec.c b/drivers/media/platform/qcom/iris/iris_vdec.c
> > index d670b51c5839..1e9ffdbb6e18 100644
> > --- a/drivers/media/platform/qcom/iris/iris_vdec.c
> > +++ b/drivers/media/platform/qcom/iris/iris_vdec.c
> > @@ -191,8 +191,6 @@ int iris_vdec_s_fmt(struct iris_inst *inst, struct v4l2_format *f)
> >  	u32 codec_align;
> >  
> >  	q = v4l2_m2m_get_vq(inst->m2m_ctx, f->type);
> > -	if (!q)
> > -		return -EINVAL;
> >  
> >  	if (vb2_is_busy(q))
> >  		return -EBUSY;
> 
> The same change would be required for iris_venc.c as well which is part of
> linux-next[1]

Thank you for noticing. I'll rebase this series on v6.18-rc1 once it
gets released and will make sure iris_venc.c is addressed.

> [1]: https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/tree/drivers/media/platform/qcom/iris/iris_venc.c#n271

-- 
Regards,

Laurent Pinchart

^ permalink raw reply	[flat|nested] 42+ messages in thread

end of thread, other threads:[~2025-10-10 11:14 UTC | newest]

Thread overview: 42+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox