* [PATCH 00/25] media: v4l2-mem2mem: Reduce cargo-cult
@ 2025-10-08 17:50 Laurent Pinchart
2025-10-08 17:50 ` [PATCH 11/25] media: imx-jpeg: Drop unneeded v4l2_m2m_get_vq() NULL check Laurent Pinchart
` (3 more replies)
0 siblings, 4 replies; 10+ 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] 10+ 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
@ 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
` (2 subsequent siblings)
3 siblings, 1 reply; 10+ 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] 10+ 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
2025-10-08 17:50 ` [PATCH 11/25] media: imx-jpeg: Drop unneeded v4l2_m2m_get_vq() NULL check 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
2025-10-08 18:24 ` [PATCH 00/25] media: v4l2-mem2mem: Reduce cargo-cult Nicolas Dufresne
3 siblings, 2 replies; 10+ 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] 10+ 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
2025-10-08 17:50 ` [PATCH 11/25] media: imx-jpeg: Drop unneeded v4l2_m2m_get_vq() NULL check Laurent Pinchart
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 18:24 ` [PATCH 00/25] media: v4l2-mem2mem: Reduce cargo-cult Nicolas Dufresne
3 siblings, 1 reply; 10+ 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] 10+ 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
` (2 preceding siblings ...)
2025-10-08 17:50 ` [PATCH 13/25] media: nxp: imx8-isi: " Laurent Pinchart
@ 2025-10-08 18:24 ` Nicolas Dufresne
2025-10-08 19:21 ` Laurent Pinchart
3 siblings, 1 reply; 10+ 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] 10+ 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; 10+ 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] 10+ 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: Drop unneeded v4l2_m2m_get_vq() NULL check Laurent Pinchart
@ 2025-10-08 20:01 ` Frank Li
0 siblings, 0 replies; 10+ 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] 10+ 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; 10+ 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] 10+ 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; 10+ 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] 10+ 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; 10+ 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] 10+ messages in thread
end of thread, other threads:[~2025-10-09 8:11 UTC | newest]
Thread overview: 10+ 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 11/25] media: imx-jpeg: Drop unneeded v4l2_m2m_get_vq() NULL check 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 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;
as well as URLs for NNTP newsgroup(s).