2021-01-11 14:58:21

by Ricardo Ribalda

[permalink] [raw]
Subject: [PATCH 1/9] media: ipu3-cio2: Do not zero reserved fields

Core code already clears reserved fields of struct
v4l2_pix_format_mplane, check: 4e1e0eb0e074 ("media: v4l2-ioctl: Zero
v4l2_plane_pix_format reserved fields").

Cc: Sakari Ailus <[email protected]>
Signed-off-by: Ricardo Ribalda <[email protected]>
---
drivers/media/pci/intel/ipu3/ipu3-cio2.c | 3 ---
1 file changed, 3 deletions(-)

diff --git a/drivers/media/pci/intel/ipu3/ipu3-cio2.c b/drivers/media/pci/intel/ipu3/ipu3-cio2.c
index 36e354ecf71e..c5376de8cb8a 100644
--- a/drivers/media/pci/intel/ipu3/ipu3-cio2.c
+++ b/drivers/media/pci/intel/ipu3/ipu3-cio2.c
@@ -1094,12 +1094,9 @@ static int cio2_v4l2_try_fmt(struct file *file, void *fh, struct v4l2_format *f)
mpix->pixelformat = fmt->fourcc;
mpix->colorspace = V4L2_COLORSPACE_RAW;
mpix->field = V4L2_FIELD_NONE;
- memset(mpix->reserved, 0, sizeof(mpix->reserved));
mpix->plane_fmt[0].bytesperline = cio2_bytesperline(mpix->width);
mpix->plane_fmt[0].sizeimage = mpix->plane_fmt[0].bytesperline *
mpix->height;
- memset(mpix->plane_fmt[0].reserved, 0,
- sizeof(mpix->plane_fmt[0].reserved));

/* use default */
mpix->ycbcr_enc = V4L2_YCBCR_ENC_DEFAULT;
--
2.30.0.284.gd98b1dd5eaa7-goog


2021-01-11 14:59:04

by Ricardo Ribalda

[permalink] [raw]
Subject: [PATCH 3/9] media: mtk-vcodec: Do not zero reserved fields

Core code already clears reserved fields of struct
v4l2_pix_format_mplane, check: 4e1e0eb0e074 ("media: v4l2-ioctl: Zero
v4l2_plane_pix_format reserved fields").

Cc: Matthias Brugger <[email protected]>
Signed-off-by: Ricardo Ribalda <[email protected]>
---
drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c | 5 -----
drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c | 8 --------
2 files changed, 13 deletions(-)

diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c
index c768a587a944..d746c41ea805 100644
--- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c
+++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c
@@ -715,12 +715,7 @@ static int vidioc_try_fmt(struct v4l2_format *f,
}
}

- for (i = 0; i < pix_fmt_mp->num_planes; i++)
- memset(&(pix_fmt_mp->plane_fmt[i].reserved[0]), 0x0,
- sizeof(pix_fmt_mp->plane_fmt[0].reserved));
-
pix_fmt_mp->flags = 0;
- memset(&pix_fmt_mp->reserved, 0x0, sizeof(pix_fmt_mp->reserved));
return 0;
}

diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c b/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c
index 21de1431cfcb..db1f62cc38b3 100644
--- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c
+++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c
@@ -320,13 +320,7 @@ static int vidioc_try_fmt(struct v4l2_format *f,
}
}

- for (i = 0; i < pix_fmt_mp->num_planes; i++)
- memset(&(pix_fmt_mp->plane_fmt[i].reserved[0]), 0x0,
- sizeof(pix_fmt_mp->plane_fmt[0].reserved));
-
pix_fmt_mp->flags = 0;
- memset(&pix_fmt_mp->reserved, 0x0,
- sizeof(pix_fmt_mp->reserved));

return 0;
}
@@ -532,8 +526,6 @@ static int vidioc_venc_g_fmt(struct file *file, void *priv,
for (i = 0; i < pix->num_planes; i++) {
pix->plane_fmt[i].bytesperline = q_data->bytesperline[i];
pix->plane_fmt[i].sizeimage = q_data->sizeimage[i];
- memset(&(pix->plane_fmt[i].reserved[0]), 0x0,
- sizeof(pix->plane_fmt[i].reserved));
}

pix->flags = 0;
--
2.30.0.284.gd98b1dd5eaa7-goog

2021-01-11 14:59:09

by Ricardo Ribalda

[permalink] [raw]
Subject: [PATCH 8/9] media: vicodec: Do not zero reserved fields

Core code already clears reserved fields of struct
v4l2_pix_format_mplane, check: 4e1e0eb0e074 ("media: v4l2-ioctl: Zero
v4l2_plane_pix_format reserved fields").

Cc: Hans Verkuil <[email protected]>
Signed-off-by: Ricardo Ribalda <[email protected]>
---
drivers/media/test-drivers/vicodec/vicodec-core.c | 5 -----
1 file changed, 5 deletions(-)

diff --git a/drivers/media/test-drivers/vicodec/vicodec-core.c b/drivers/media/test-drivers/vicodec/vicodec-core.c
index 025f3ff77302..33f1c893c1b6 100644
--- a/drivers/media/test-drivers/vicodec/vicodec-core.c
+++ b/drivers/media/test-drivers/vicodec/vicodec-core.c
@@ -811,9 +811,6 @@ static int vidioc_g_fmt(struct vicodec_ctx *ctx, struct v4l2_format *f)
pix_mp->xfer_func = ctx->state.xfer_func;
pix_mp->ycbcr_enc = ctx->state.ycbcr_enc;
pix_mp->quantization = ctx->state.quantization;
- memset(pix_mp->reserved, 0, sizeof(pix_mp->reserved));
- memset(pix_mp->plane_fmt[0].reserved, 0,
- sizeof(pix_mp->plane_fmt[0].reserved));
break;
default:
return -EINVAL;
@@ -886,8 +883,6 @@ static int vidioc_try_fmt(struct vicodec_ctx *ctx, struct v4l2_format *f)
info->sizeimage_mult / info->sizeimage_div;
if (pix_mp->pixelformat == V4L2_PIX_FMT_FWHT)
plane->sizeimage += sizeof(struct fwht_cframe_hdr);
- memset(pix_mp->reserved, 0, sizeof(pix_mp->reserved));
- memset(plane->reserved, 0, sizeof(plane->reserved));
break;
default:
return -EINVAL;
--
2.30.0.284.gd98b1dd5eaa7-goog

2021-01-11 14:59:09

by Ricardo Ribalda

[permalink] [raw]
Subject: [PATCH 5/9] media: jpu: Do not zero reserved fields

Core code already clears reserved fields of struct
v4l2_pix_format_mplane, check: 4e1e0eb0e074 ("media: v4l2-ioctl: Zero
v4l2_plane_pix_format reserved fields").

Cc: Mikhail Ulyanov <[email protected]>
Signed-off-by: Ricardo Ribalda <[email protected]>
---
drivers/media/platform/rcar_jpu.c | 5 -----
1 file changed, 5 deletions(-)

diff --git a/drivers/media/platform/rcar_jpu.c b/drivers/media/platform/rcar_jpu.c
index 9b99ff368698..2bddc957cb87 100644
--- a/drivers/media/platform/rcar_jpu.c
+++ b/drivers/media/platform/rcar_jpu.c
@@ -793,7 +793,6 @@ static int __jpu_try_fmt(struct jpu_ctx *ctx, struct jpu_fmt **fmtinfo,
pix->colorspace = fmt->colorspace;
pix->field = V4L2_FIELD_NONE;
pix->num_planes = fmt->num_planes;
- memset(pix->reserved, 0, sizeof(pix->reserved));

jpu_bound_align_image(&pix->width, JPU_WIDTH_MIN, JPU_WIDTH_MAX,
fmt->h_align, &pix->height, JPU_HEIGHT_MIN,
@@ -808,8 +807,6 @@ static int __jpu_try_fmt(struct jpu_ctx *ctx, struct jpu_fmt **fmtinfo,
pix->plane_fmt[0].sizeimage = JPU_JPEG_HDR_SIZE +
(JPU_JPEG_MAX_BYTES_PER_PIXEL * w * h);
pix->plane_fmt[0].bytesperline = 0;
- memset(pix->plane_fmt[0].reserved, 0,
- sizeof(pix->plane_fmt[0].reserved));
} else {
unsigned int i, bpl = 0;

@@ -822,8 +819,6 @@ static int __jpu_try_fmt(struct jpu_ctx *ctx, struct jpu_fmt **fmtinfo,
for (i = 0; i < pix->num_planes; ++i) {
pix->plane_fmt[i].bytesperline = bpl;
pix->plane_fmt[i].sizeimage = bpl * h * fmt->bpp[i] / 8;
- memset(pix->plane_fmt[i].reserved, 0,
- sizeof(pix->plane_fmt[i].reserved));
}
}

--
2.30.0.284.gd98b1dd5eaa7-goog

2021-01-11 14:59:27

by Ricardo Ribalda

[permalink] [raw]
Subject: [PATCH 7/9] media: ti-vpe: Do not zero reserved fields

Core code already clears reserved fields of struct
v4l2_pix_format_mplane, check: 4e1e0eb0e074 ("media: v4l2-ioctl: Zero
v4l2_plane_pix_format reserved fields").

Cc: Benoit Parrot <[email protected]>
Signed-off-by: Ricardo Ribalda <[email protected]>
---
drivers/media/platform/ti-vpe/vpe.c | 2 --
1 file changed, 2 deletions(-)

diff --git a/drivers/media/platform/ti-vpe/vpe.c b/drivers/media/platform/ti-vpe/vpe.c
index 779dd74b82d0..10251b787674 100644
--- a/drivers/media/platform/ti-vpe/vpe.c
+++ b/drivers/media/platform/ti-vpe/vpe.c
@@ -1683,7 +1683,6 @@ static int __vpe_try_fmt(struct vpe_ctx *ctx, struct v4l2_format *f,
}
}

- memset(pix->reserved, 0, sizeof(pix->reserved));
for (i = 0; i < pix->num_planes; i++) {
plane_fmt = &pix->plane_fmt[i];
depth = fmt->vpdma_fmt[i]->depth;
@@ -1713,7 +1712,6 @@ static int __vpe_try_fmt(struct vpe_ctx *ctx, struct v4l2_format *f,
plane_fmt->bytesperline *
depth) >> 3;
}
- memset(plane_fmt->reserved, 0, sizeof(plane_fmt->reserved));
}

return 0;
--
2.30.0.284.gd98b1dd5eaa7-goog

2021-01-11 14:59:49

by Ricardo Ribalda

[permalink] [raw]
Subject: [PATCH 6/9] media: sum4i-csi: Do not zero reserved fields

Core code already clears reserved fields of struct
v4l2_pix_format_mplane, check: 4e1e0eb0e074 ("media: v4l2-ioctl: Zero
v4l2_plane_pix_format reserved fields").

Cc: Maxime Ripard <[email protected]>
Cc: Chen-Yu Tsai <[email protected]>
Signed-off-by: Ricardo Ribalda <[email protected]>
---
drivers/media/platform/sunxi/sun4i-csi/sun4i_v4l2.c | 4 ----
1 file changed, 4 deletions(-)

diff --git a/drivers/media/platform/sunxi/sun4i-csi/sun4i_v4l2.c b/drivers/media/platform/sunxi/sun4i-csi/sun4i_v4l2.c
index 1a2f65d83a6c..4785faddf630 100644
--- a/drivers/media/platform/sunxi/sun4i-csi/sun4i_v4l2.c
+++ b/drivers/media/platform/sunxi/sun4i-csi/sun4i_v4l2.c
@@ -113,8 +113,6 @@ static void _sun4i_csi_try_fmt(struct sun4i_csi *csi,
pix->num_planes = _fmt->num_planes;
pix->pixelformat = _fmt->fourcc;

- memset(pix->reserved, 0, sizeof(pix->reserved));
-
/* Align the width and height on the subsampling */
width = ALIGN(pix->width, _fmt->hsub);
height = ALIGN(pix->height, _fmt->vsub);
@@ -131,8 +129,6 @@ static void _sun4i_csi_try_fmt(struct sun4i_csi *csi,
bpl = pix->width / hsub * _fmt->bpp[i] / 8;
pix->plane_fmt[i].bytesperline = bpl;
pix->plane_fmt[i].sizeimage = bpl * pix->height / vsub;
- memset(pix->plane_fmt[i].reserved, 0,
- sizeof(pix->plane_fmt[i].reserved));
}
}

--
2.30.0.284.gd98b1dd5eaa7-goog

2021-01-11 14:59:57

by Ricardo Ribalda

[permalink] [raw]
Subject: [PATCH 4/9] media: fdp1: Do not zero reserved fields

Core code already clears reserved fields of struct
v4l2_pix_format_mplane, check: 4e1e0eb0e074 ("media: v4l2-ioctl: Zero
v4l2_plane_pix_format reserved fields").

Cc: [email protected]
Signed-off-by: Ricardo Ribalda <[email protected]>
---
drivers/media/platform/rcar_fdp1.c | 4 ----
1 file changed, 4 deletions(-)

diff --git a/drivers/media/platform/rcar_fdp1.c b/drivers/media/platform/rcar_fdp1.c
index c9448de885b6..01c1fbb97bf6 100644
--- a/drivers/media/platform/rcar_fdp1.c
+++ b/drivers/media/platform/rcar_fdp1.c
@@ -1439,8 +1439,6 @@ static void fdp1_compute_stride(struct v4l2_pix_format_mplane *pix,
pix->plane_fmt[i].sizeimage = pix->plane_fmt[i].bytesperline
* pix->height / vsub;

- memset(pix->plane_fmt[i].reserved, 0,
- sizeof(pix->plane_fmt[i].reserved));
}

if (fmt->num_planes == 3) {
@@ -1448,8 +1446,6 @@ static void fdp1_compute_stride(struct v4l2_pix_format_mplane *pix,
pix->plane_fmt[2].bytesperline = pix->plane_fmt[1].bytesperline;
pix->plane_fmt[2].sizeimage = pix->plane_fmt[1].sizeimage;

- memset(pix->plane_fmt[2].reserved, 0,
- sizeof(pix->plane_fmt[2].reserved));
}
}

--
2.30.0.284.gd98b1dd5eaa7-goog

2021-01-11 15:01:29

by Ricardo Ribalda

[permalink] [raw]
Subject: [PATCH 9/9] media: staging/intel-ipu3 : Do not zero reserved fields

Core code already clears reserved fields of struct
v4l2_pix_format_mplane, check: 4e1e0eb0e074 ("media: v4l2-ioctl: Zero
v4l2_plane_pix_format reserved fields").

Cc: Sakari Ailus <[email protected]>
Signed-off-by: Ricardo Ribalda <[email protected]>
---
drivers/staging/media/ipu3/ipu3-v4l2.c | 3 ---
1 file changed, 3 deletions(-)

diff --git a/drivers/staging/media/ipu3/ipu3-v4l2.c b/drivers/staging/media/ipu3/ipu3-v4l2.c
index 4dc8d9165f63..60aa02eb7d2a 100644
--- a/drivers/staging/media/ipu3/ipu3-v4l2.c
+++ b/drivers/staging/media/ipu3/ipu3-v4l2.c
@@ -773,9 +773,6 @@ static int imgu_try_fmt(struct file *file, void *fh, struct v4l2_format *f)

pixm->pixelformat = fmt->fourcc;

- memset(pixm->plane_fmt[0].reserved, 0,
- sizeof(pixm->plane_fmt[0].reserved));
-
return 0;
}

--
2.30.0.284.gd98b1dd5eaa7-goog

2021-01-11 18:14:28

by Ezequiel Garcia

[permalink] [raw]
Subject: Re: [PATCH 6/9] media: sum4i-csi: Do not zero reserved fields

Hi Ricardo,

Thanks a lot for doing this media-wide cleanup.

Aside from a silly typo here in the commit title, s/sum4i-csi/sun4i-csi,
all the patches seem fine.

Thanks,
Ezequiel

On Mon, 11 Jan 2021 at 11:56, Ricardo Ribalda <[email protected]> wrote:
>
> Core code already clears reserved fields of struct
> v4l2_pix_format_mplane, check: 4e1e0eb0e074 ("media: v4l2-ioctl: Zero
> v4l2_plane_pix_format reserved fields").
>
> Cc: Maxime Ripard <[email protected]>
> Cc: Chen-Yu Tsai <[email protected]>
> Signed-off-by: Ricardo Ribalda <[email protected]>
> ---
> drivers/media/platform/sunxi/sun4i-csi/sun4i_v4l2.c | 4 ----
> 1 file changed, 4 deletions(-)
>
> diff --git a/drivers/media/platform/sunxi/sun4i-csi/sun4i_v4l2.c b/drivers/media/platform/sunxi/sun4i-csi/sun4i_v4l2.c
> index 1a2f65d83a6c..4785faddf630 100644
> --- a/drivers/media/platform/sunxi/sun4i-csi/sun4i_v4l2.c
> +++ b/drivers/media/platform/sunxi/sun4i-csi/sun4i_v4l2.c
> @@ -113,8 +113,6 @@ static void _sun4i_csi_try_fmt(struct sun4i_csi *csi,
> pix->num_planes = _fmt->num_planes;
> pix->pixelformat = _fmt->fourcc;
>
> - memset(pix->reserved, 0, sizeof(pix->reserved));
> -
> /* Align the width and height on the subsampling */
> width = ALIGN(pix->width, _fmt->hsub);
> height = ALIGN(pix->height, _fmt->vsub);
> @@ -131,8 +129,6 @@ static void _sun4i_csi_try_fmt(struct sun4i_csi *csi,
> bpl = pix->width / hsub * _fmt->bpp[i] / 8;
> pix->plane_fmt[i].bytesperline = bpl;
> pix->plane_fmt[i].sizeimage = bpl * pix->height / vsub;
> - memset(pix->plane_fmt[i].reserved, 0,
> - sizeof(pix->plane_fmt[i].reserved));
> }
> }
>
> --
> 2.30.0.284.gd98b1dd5eaa7-goog
>

2021-01-12 13:01:19

by Kieran Bingham

[permalink] [raw]
Subject: Re: [PATCH 4/9] media: fdp1: Do not zero reserved fields

Hi Ricardo,

On 11/01/2021 14:54, Ricardo Ribalda wrote:
> Core code already clears reserved fields of struct
> v4l2_pix_format_mplane, check: 4e1e0eb0e074 ("media: v4l2-ioctl: Zero
> v4l2_plane_pix_format reserved fields").
>
> Cc: [email protected]
> Signed-off-by: Ricardo Ribalda <[email protected]>

I love a good cleanup series.

Reviewed-by: Kieran Bingham <[email protected]>

> ---
> drivers/media/platform/rcar_fdp1.c | 4 ----
> 1 file changed, 4 deletions(-)
>
> diff --git a/drivers/media/platform/rcar_fdp1.c b/drivers/media/platform/rcar_fdp1.c
> index c9448de885b6..01c1fbb97bf6 100644
> --- a/drivers/media/platform/rcar_fdp1.c
> +++ b/drivers/media/platform/rcar_fdp1.c
> @@ -1439,8 +1439,6 @@ static void fdp1_compute_stride(struct v4l2_pix_format_mplane *pix,
> pix->plane_fmt[i].sizeimage = pix->plane_fmt[i].bytesperline
> * pix->height / vsub;
>
> - memset(pix->plane_fmt[i].reserved, 0,
> - sizeof(pix->plane_fmt[i].reserved));
> }
>
> if (fmt->num_planes == 3) {
> @@ -1448,8 +1446,6 @@ static void fdp1_compute_stride(struct v4l2_pix_format_mplane *pix,
> pix->plane_fmt[2].bytesperline = pix->plane_fmt[1].bytesperline;
> pix->plane_fmt[2].sizeimage = pix->plane_fmt[1].sizeimage;
>
> - memset(pix->plane_fmt[2].reserved, 0,
> - sizeof(pix->plane_fmt[2].reserved));
> }
> }
>
>

2021-01-12 13:03:05

by Kieran Bingham

[permalink] [raw]
Subject: Re: [PATCH 5/9] media: jpu: Do not zero reserved fields

Hi Ricardo,

On 11/01/2021 14:54, Ricardo Ribalda wrote:
> Core code already clears reserved fields of struct
> v4l2_pix_format_mplane, check: 4e1e0eb0e074 ("media: v4l2-ioctl: Zero
> v4l2_plane_pix_format reserved fields").
>
> Cc: Mikhail Ulyanov <[email protected]>
> Signed-off-by: Ricardo Ribalda <[email protected]>
> ---
> drivers/media/platform/rcar_jpu.c | 5 -----
> 1 file changed, 5 deletions(-)
>
> diff --git a/drivers/media/platform/rcar_jpu.c b/drivers/media/platform/rcar_jpu.c
> index 9b99ff368698..2bddc957cb87 100644
> --- a/drivers/media/platform/rcar_jpu.c
> +++ b/drivers/media/platform/rcar_jpu.c

There's a memset(cap->reserved...) in jpu_querycap()

Is that also applicable and covered by the core?

Looking at v4l_querycap() it doesn't seem to be so:


Reviewed-by: Kieran Bingham <[email protected]>

> @@ -793,7 +793,6 @@ static int __jpu_try_fmt(struct jpu_ctx *ctx, struct jpu_fmt **fmtinfo,
> pix->colorspace = fmt->colorspace;
> pix->field = V4L2_FIELD_NONE;
> pix->num_planes = fmt->num_planes;
> - memset(pix->reserved, 0, sizeof(pix->reserved));
>
> jpu_bound_align_image(&pix->width, JPU_WIDTH_MIN, JPU_WIDTH_MAX,
> fmt->h_align, &pix->height, JPU_HEIGHT_MIN,
> @@ -808,8 +807,6 @@ static int __jpu_try_fmt(struct jpu_ctx *ctx, struct jpu_fmt **fmtinfo,
> pix->plane_fmt[0].sizeimage = JPU_JPEG_HDR_SIZE +
> (JPU_JPEG_MAX_BYTES_PER_PIXEL * w * h);
> pix->plane_fmt[0].bytesperline = 0;
> - memset(pix->plane_fmt[0].reserved, 0,
> - sizeof(pix->plane_fmt[0].reserved));
> } else {
> unsigned int i, bpl = 0;
>
> @@ -822,8 +819,6 @@ static int __jpu_try_fmt(struct jpu_ctx *ctx, struct jpu_fmt **fmtinfo,
> for (i = 0; i < pix->num_planes; ++i) {
> pix->plane_fmt[i].bytesperline = bpl;
> pix->plane_fmt[i].sizeimage = bpl * h * fmt->bpp[i] / 8;
> - memset(pix->plane_fmt[i].reserved, 0,
> - sizeof(pix->plane_fmt[i].reserved));
> }
> }
>
>

2021-01-12 13:03:18

by Kieran Bingham

[permalink] [raw]
Subject: Re: [PATCH 6/9] media: sum4i-csi: Do not zero reserved fields

Hi Ricardo,

Well I've started, so I may as well finish and do the rest too.

On 11/01/2021 14:54, Ricardo Ribalda wrote:
> Core code already clears reserved fields of struct
> v4l2_pix_format_mplane, check: 4e1e0eb0e074 ("media: v4l2-ioctl: Zero
> v4l2_plane_pix_format reserved fields").

Indeed, these are the only memsets here ...

With the $TITLE fixed as spotted by Ezequiel,

Reviewed-by: Kieran Bingham <[email protected]>

>
> Cc: Maxime Ripard <[email protected]>
> Cc: Chen-Yu Tsai <[email protected]>
> Signed-off-by: Ricardo Ribalda <[email protected]>
> ---
> drivers/media/platform/sunxi/sun4i-csi/sun4i_v4l2.c | 4 ----
> 1 file changed, 4 deletions(-)
>
> diff --git a/drivers/media/platform/sunxi/sun4i-csi/sun4i_v4l2.c b/drivers/media/platform/sunxi/sun4i-csi/sun4i_v4l2.c
> index 1a2f65d83a6c..4785faddf630 100644
> --- a/drivers/media/platform/sunxi/sun4i-csi/sun4i_v4l2.c
> +++ b/drivers/media/platform/sunxi/sun4i-csi/sun4i_v4l2.c
> @@ -113,8 +113,6 @@ static void _sun4i_csi_try_fmt(struct sun4i_csi *csi,
> pix->num_planes = _fmt->num_planes;
> pix->pixelformat = _fmt->fourcc;
>
> - memset(pix->reserved, 0, sizeof(pix->reserved));
> -
> /* Align the width and height on the subsampling */
> width = ALIGN(pix->width, _fmt->hsub);
> height = ALIGN(pix->height, _fmt->vsub);
> @@ -131,8 +129,6 @@ static void _sun4i_csi_try_fmt(struct sun4i_csi *csi,
> bpl = pix->width / hsub * _fmt->bpp[i] / 8;
> pix->plane_fmt[i].bytesperline = bpl;
> pix->plane_fmt[i].sizeimage = bpl * pix->height / vsub;
> - memset(pix->plane_fmt[i].reserved, 0,
> - sizeof(pix->plane_fmt[i].reserved));
> }
> }
>
>

2021-01-12 13:04:43

by Kieran Bingham

[permalink] [raw]
Subject: Re: [PATCH 8/9] media: vicodec: Do not zero reserved fields

Hi Ricardo,

On 11/01/2021 14:54, Ricardo Ribalda wrote:
> Core code already clears reserved fields of struct
> v4l2_pix_format_mplane, check: 4e1e0eb0e074 ("media: v4l2-ioctl: Zero
> v4l2_plane_pix_format reserved fields").
>
> Cc: Hans Verkuil <[email protected]>
> Signed-off-by: Ricardo Ribalda <[email protected]>

Reviewed-by: Kieran Bingham <[email protected]>


> ---
> drivers/media/test-drivers/vicodec/vicodec-core.c | 5 -----
> 1 file changed, 5 deletions(-)
>
> diff --git a/drivers/media/test-drivers/vicodec/vicodec-core.c b/drivers/media/test-drivers/vicodec/vicodec-core.c
> index 025f3ff77302..33f1c893c1b6 100644
> --- a/drivers/media/test-drivers/vicodec/vicodec-core.c
> +++ b/drivers/media/test-drivers/vicodec/vicodec-core.c
> @@ -811,9 +811,6 @@ static int vidioc_g_fmt(struct vicodec_ctx *ctx, struct v4l2_format *f)
> pix_mp->xfer_func = ctx->state.xfer_func;
> pix_mp->ycbcr_enc = ctx->state.ycbcr_enc;
> pix_mp->quantization = ctx->state.quantization;
> - memset(pix_mp->reserved, 0, sizeof(pix_mp->reserved));
> - memset(pix_mp->plane_fmt[0].reserved, 0,
> - sizeof(pix_mp->plane_fmt[0].reserved));
> break;
> default:
> return -EINVAL;
> @@ -886,8 +883,6 @@ static int vidioc_try_fmt(struct vicodec_ctx *ctx, struct v4l2_format *f)
> info->sizeimage_mult / info->sizeimage_div;
> if (pix_mp->pixelformat == V4L2_PIX_FMT_FWHT)
> plane->sizeimage += sizeof(struct fwht_cframe_hdr);
> - memset(pix_mp->reserved, 0, sizeof(pix_mp->reserved));
> - memset(plane->reserved, 0, sizeof(plane->reserved));
> break;
> default:
> return -EINVAL;
>

2021-01-12 13:05:19

by Kieran Bingham

[permalink] [raw]
Subject: Re: [PATCH 1/9] media: ipu3-cio2: Do not zero reserved fields

Hi Ricardo,

On 11/01/2021 14:54, Ricardo Ribalda wrote:
> Core code already clears reserved fields of struct
> v4l2_pix_format_mplane, check: 4e1e0eb0e074 ("media: v4l2-ioctl: Zero
> v4l2_plane_pix_format reserved fields").
>
> Cc: Sakari Ailus <[email protected]>
> Signed-off-by: Ricardo Ribalda <[email protected]>

Reviewed-by: Kieran Bingham <[email protected]>

> ---
> drivers/media/pci/intel/ipu3/ipu3-cio2.c | 3 ---
> 1 file changed, 3 deletions(-)
>
> diff --git a/drivers/media/pci/intel/ipu3/ipu3-cio2.c b/drivers/media/pci/intel/ipu3/ipu3-cio2.c
> index 36e354ecf71e..c5376de8cb8a 100644
> --- a/drivers/media/pci/intel/ipu3/ipu3-cio2.c
> +++ b/drivers/media/pci/intel/ipu3/ipu3-cio2.c
> @@ -1094,12 +1094,9 @@ static int cio2_v4l2_try_fmt(struct file *file, void *fh, struct v4l2_format *f)
> mpix->pixelformat = fmt->fourcc;
> mpix->colorspace = V4L2_COLORSPACE_RAW;
> mpix->field = V4L2_FIELD_NONE;
> - memset(mpix->reserved, 0, sizeof(mpix->reserved));
> mpix->plane_fmt[0].bytesperline = cio2_bytesperline(mpix->width);
> mpix->plane_fmt[0].sizeimage = mpix->plane_fmt[0].bytesperline *
> mpix->height;
> - memset(mpix->plane_fmt[0].reserved, 0,
> - sizeof(mpix->plane_fmt[0].reserved));
>
> /* use default */
> mpix->ycbcr_enc = V4L2_YCBCR_ENC_DEFAULT;
>

2021-01-12 13:06:00

by Kieran Bingham

[permalink] [raw]
Subject: Re: [PATCH 9/9] media: staging/intel-ipu3 : Do not zero reserved fields

Hi Ricardo,

On 11/01/2021 14:54, Ricardo Ribalda wrote:
> Core code already clears reserved fields of struct
> v4l2_pix_format_mplane, check: 4e1e0eb0e074 ("media: v4l2-ioctl: Zero
> v4l2_plane_pix_format reserved fields").
>
> Cc: Sakari Ailus <[email protected]>
> Signed-off-by: Ricardo Ribalda <[email protected]>
> ---
> drivers/staging/media/ipu3/ipu3-v4l2.c | 3 ---
> 1 file changed, 3 deletions(-)
>
> diff --git a/drivers/staging/media/ipu3/ipu3-v4l2.c b/drivers/staging/media/ipu3/ipu3-v4l2.c
> index 4dc8d9165f63..60aa02eb7d2a 100644
> --- a/drivers/staging/media/ipu3/ipu3-v4l2.c
> +++ b/drivers/staging/media/ipu3/ipu3-v4l2.c

The ipu3-css.c also has a memset on the plane formats in the
migu_css_queue_init(), but that's possibly still out of scope for this
patch ('just')

struct v4l2_pix_format_mplane *const f = &queue->fmt.mpix;
memset(f->reserved, 0, sizeof(f->reserved));

I can't yet see anything that clears the reserved formats on queue
initialisations, so I don't think we can remove that yet unless I've
missed something anyway.

Seems like there is a lot more that could be cleared in core ...

But - as I said, I think that's out of scope here so

Reviewed-by: Kieran Bingham <[email protected]>

> @@ -773,9 +773,6 @@ static int imgu_try_fmt(struct file *file, void *fh, struct v4l2_format *f)
>
> pixm->pixelformat = fmt->fourcc;
>
> - memset(pixm->plane_fmt[0].reserved, 0,
> - sizeof(pixm->plane_fmt[0].reserved));
> -
> return 0;
> }
>
>

2021-01-12 13:07:08

by Kieran Bingham

[permalink] [raw]
Subject: Re: [PATCH 3/9] media: mtk-vcodec: Do not zero reserved fields

Hi Ricardo,

On 11/01/2021 14:54, Ricardo Ribalda wrote:
> Core code already clears reserved fields of struct
> v4l2_pix_format_mplane, check: 4e1e0eb0e074 ("media: v4l2-ioctl: Zero
> v4l2_plane_pix_format reserved fields").
>
> Cc: Matthias Brugger <[email protected]>
> Signed-off-by: Ricardo Ribalda <[email protected]>

There's also another memset.*reserved occurring in
platform/mtk-vcodec/mtk_vcodec_enc.c: vidioc_enum_fmt()

While v4l2-core/v4l2-ioctl.c has:
> static int v4l_enum_fmt(const struct v4l2_ioctl_ops *ops,
> struct file *file, void *fh, void *arg)
> {
> struct video_device *vdev = video_devdata(file);
> struct v4l2_fmtdesc *p = arg;
> int ret = check_fmt(file, p->type);
> u32 mbus_code;
> u32 cap_mask;
>
> if (ret)
> return ret;
> ret = -EINVAL;
>
> if (!(vdev->device_caps & V4L2_CAP_IO_MC))
> p->mbus_code = 0;
>
> mbus_code = p->mbus_code;
> CLEAR_AFTER_FIELD(p, type);

So would that mean ^^^ should also be sufficient to remove the need for
that memset?

With that fixed or resolved:

Reviewed-by: Kieran Bingham <[email protected]>



> ---
> drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c | 5 -----
> drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c | 8 --------
> 2 files changed, 13 deletions(-)
>
> diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c
> index c768a587a944..d746c41ea805 100644
> --- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c
> +++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c
> @@ -715,12 +715,7 @@ static int vidioc_try_fmt(struct v4l2_format *f,
> }
> }
>
> - for (i = 0; i < pix_fmt_mp->num_planes; i++)
> - memset(&(pix_fmt_mp->plane_fmt[i].reserved[0]), 0x0,
> - sizeof(pix_fmt_mp->plane_fmt[0].reserved));
> -
> pix_fmt_mp->flags = 0;
> - memset(&pix_fmt_mp->reserved, 0x0, sizeof(pix_fmt_mp->reserved));
> return 0;
> }
>
> diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c b/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c
> index 21de1431cfcb..db1f62cc38b3 100644
> --- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c
> +++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c
> @@ -320,13 +320,7 @@ static int vidioc_try_fmt(struct v4l2_format *f,
> }
> }
>
> - for (i = 0; i < pix_fmt_mp->num_planes; i++)
> - memset(&(pix_fmt_mp->plane_fmt[i].reserved[0]), 0x0,
> - sizeof(pix_fmt_mp->plane_fmt[0].reserved));
> -
> pix_fmt_mp->flags = 0;
> - memset(&pix_fmt_mp->reserved, 0x0,
> - sizeof(pix_fmt_mp->reserved));
>
> return 0;
> }
> @@ -532,8 +526,6 @@ static int vidioc_venc_g_fmt(struct file *file, void *priv,
> for (i = 0; i < pix->num_planes; i++) {
> pix->plane_fmt[i].bytesperline = q_data->bytesperline[i];
> pix->plane_fmt[i].sizeimage = q_data->sizeimage[i];
> - memset(&(pix->plane_fmt[i].reserved[0]), 0x0,
> - sizeof(pix->plane_fmt[i].reserved));
> }
>
> pix->flags = 0;
>

2021-01-13 01:33:16

by Kieran Bingham

[permalink] [raw]
Subject: Re: [PATCH 7/9] media: ti-vpe: Do not zero reserved fields

Hi Ricardo,

On 11/01/2021 14:54, Ricardo Ribalda wrote:
> Core code already clears reserved fields of struct
> v4l2_pix_format_mplane, check: 4e1e0eb0e074 ("media: v4l2-ioctl: Zero
> v4l2_plane_pix_format reserved fields").


Reviewed-by: Kieran Bingham <[email protected]>

> Cc: Benoit Parrot <[email protected]>
> Signed-off-by: Ricardo Ribalda <[email protected]>
> ---
> drivers/media/platform/ti-vpe/vpe.c | 2 --
> 1 file changed, 2 deletions(-)
>
> diff --git a/drivers/media/platform/ti-vpe/vpe.c b/drivers/media/platform/ti-vpe/vpe.c
> index 779dd74b82d0..10251b787674 100644
> --- a/drivers/media/platform/ti-vpe/vpe.c
> +++ b/drivers/media/platform/ti-vpe/vpe.c
> @@ -1683,7 +1683,6 @@ static int __vpe_try_fmt(struct vpe_ctx *ctx, struct v4l2_format *f,
> }
> }
>
> - memset(pix->reserved, 0, sizeof(pix->reserved));
> for (i = 0; i < pix->num_planes; i++) {
> plane_fmt = &pix->plane_fmt[i];
> depth = fmt->vpdma_fmt[i]->depth;
> @@ -1713,7 +1712,6 @@ static int __vpe_try_fmt(struct vpe_ctx *ctx, struct v4l2_format *f,
> plane_fmt->bytesperline *
> depth) >> 3;
> }
> - memset(plane_fmt->reserved, 0, sizeof(plane_fmt->reserved));
> }
>
> return 0;
>

2021-01-21 10:05:59

by Hans Verkuil

[permalink] [raw]
Subject: Re: [PATCH 5/9] media: jpu: Do not zero reserved fields

On 12/01/2021 12:07, Kieran Bingham wrote:
> Hi Ricardo,
>
> On 11/01/2021 14:54, Ricardo Ribalda wrote:
>> Core code already clears reserved fields of struct
>> v4l2_pix_format_mplane, check: 4e1e0eb0e074 ("media: v4l2-ioctl: Zero
>> v4l2_plane_pix_format reserved fields").
>>
>> Cc: Mikhail Ulyanov <[email protected]>
>> Signed-off-by: Ricardo Ribalda <[email protected]>
>> ---
>> drivers/media/platform/rcar_jpu.c | 5 -----
>> 1 file changed, 5 deletions(-)
>>
>> diff --git a/drivers/media/platform/rcar_jpu.c b/drivers/media/platform/rcar_jpu.c
>> index 9b99ff368698..2bddc957cb87 100644
>> --- a/drivers/media/platform/rcar_jpu.c
>> +++ b/drivers/media/platform/rcar_jpu.c
>
> There's a memset(cap->reserved...) in jpu_querycap()
>
> Is that also applicable and covered by the core?

Yes: VIDIOC_QUERYCAP is a read-only ioctl: the core will always zero
the struct in that case before handing it over to the driver.

This is something for a separate patch, though. There may well be
more drivers that do this for querycap.

Regards,

Hans

>
> Looking at v4l_querycap() it doesn't seem to be so:
>
>
> Reviewed-by: Kieran Bingham <[email protected]>
>
>> @@ -793,7 +793,6 @@ static int __jpu_try_fmt(struct jpu_ctx *ctx, struct jpu_fmt **fmtinfo,
>> pix->colorspace = fmt->colorspace;
>> pix->field = V4L2_FIELD_NONE;
>> pix->num_planes = fmt->num_planes;
>> - memset(pix->reserved, 0, sizeof(pix->reserved));
>>
>> jpu_bound_align_image(&pix->width, JPU_WIDTH_MIN, JPU_WIDTH_MAX,
>> fmt->h_align, &pix->height, JPU_HEIGHT_MIN,
>> @@ -808,8 +807,6 @@ static int __jpu_try_fmt(struct jpu_ctx *ctx, struct jpu_fmt **fmtinfo,
>> pix->plane_fmt[0].sizeimage = JPU_JPEG_HDR_SIZE +
>> (JPU_JPEG_MAX_BYTES_PER_PIXEL * w * h);
>> pix->plane_fmt[0].bytesperline = 0;
>> - memset(pix->plane_fmt[0].reserved, 0,
>> - sizeof(pix->plane_fmt[0].reserved));
>> } else {
>> unsigned int i, bpl = 0;
>>
>> @@ -822,8 +819,6 @@ static int __jpu_try_fmt(struct jpu_ctx *ctx, struct jpu_fmt **fmtinfo,
>> for (i = 0; i < pix->num_planes; ++i) {
>> pix->plane_fmt[i].bytesperline = bpl;
>> pix->plane_fmt[i].sizeimage = bpl * h * fmt->bpp[i] / 8;
>> - memset(pix->plane_fmt[i].reserved, 0,
>> - sizeof(pix->plane_fmt[i].reserved));
>> }
>> }
>>
>>
>