diff mbox series

media: coda: limit frame interval enumeration to supported encoder frame sizes

Message ID 20220426091555.2240313-1-p.zabel@pengutronix.de (mailing list archive)
State New, archived
Headers show
Series media: coda: limit frame interval enumeration to supported encoder frame sizes | expand

Commit Message

Philipp Zabel April 26, 2022, 9:15 a.m. UTC
Let VIDIOC_ENUM_FRAMEINTERVALS return -EINVAL if userspace queries
frame intervals for frame sizes unsupported by the encoder. Fixes the
following v4l2-compliance failure:

		fail: v4l2-test-formats.cpp(123): found frame intervals for invalid size 47x16
		fail: v4l2-test-formats.cpp(282): node->codec_mask & STATEFUL_ENCODER
	test VIDIOC_ENUM_FMT/FRAMESIZES/FRAMEINTERVALS: FAIL

For decoder devices, return -ENOTTY.

Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
---
 .../media/platform/chips-media/coda-common.c  | 20 +++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)

Comments

Hans Verkuil April 28, 2022, 7:51 a.m. UTC | #1
On 26/04/2022 11:15, Philipp Zabel wrote:
> Let VIDIOC_ENUM_FRAMEINTERVALS return -EINVAL if userspace queries
> frame intervals for frame sizes unsupported by the encoder. Fixes the
> following v4l2-compliance failure:
> 
> 		fail: v4l2-test-formats.cpp(123): found frame intervals for invalid size 47x16
> 		fail: v4l2-test-formats.cpp(282): node->codec_mask & STATEFUL_ENCODER
> 	test VIDIOC_ENUM_FMT/FRAMESIZES/FRAMEINTERVALS: FAIL
> 
> For decoder devices, return -ENOTTY.

Shouldn't that be 'encoder devices'?

And why mention it at all since this isn't part of the changes in this patch?

I can drop this last sentence, if you like, but before I do that I need
confirmation that that's OK.

Regards,

	Hans

> 
> Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
> ---
>  .../media/platform/chips-media/coda-common.c  | 20 +++++++++++++------
>  1 file changed, 14 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/media/platform/chips-media/coda-common.c b/drivers/media/platform/chips-media/coda-common.c
> index 7528f2718c4d..af71eea04dbd 100644
> --- a/drivers/media/platform/chips-media/coda-common.c
> +++ b/drivers/media/platform/chips-media/coda-common.c
> @@ -1315,7 +1315,8 @@ static int coda_enum_frameintervals(struct file *file, void *fh,
>  				    struct v4l2_frmivalenum *f)
>  {
>  	struct coda_ctx *ctx = fh_to_ctx(fh);
> -	int i;
> +	struct coda_q_data *q_data;
> +	const struct coda_codec *codec;
>  
>  	if (f->index)
>  		return -EINVAL;
> @@ -1324,12 +1325,19 @@ static int coda_enum_frameintervals(struct file *file, void *fh,
>  	if (!ctx->vdoa && f->pixel_format == V4L2_PIX_FMT_YUYV)
>  		return -EINVAL;
>  
> -	for (i = 0; i < CODA_MAX_FORMATS; i++) {
> -		if (f->pixel_format == ctx->cvd->src_formats[i] ||
> -		    f->pixel_format == ctx->cvd->dst_formats[i])
> -			break;
> +	if (coda_format_normalize_yuv(f->pixel_format) == V4L2_PIX_FMT_YUV420) {
> +		q_data = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE);
> +		codec = coda_find_codec(ctx->dev, f->pixel_format,
> +					q_data->fourcc);
> +	} else {
> +		codec = coda_find_codec(ctx->dev, V4L2_PIX_FMT_YUV420,
> +					f->pixel_format);
>  	}
> -	if (i == CODA_MAX_FORMATS)
> +	if (!codec)
> +		return -EINVAL;
> +
> +	if (f->width < MIN_W || f->width > codec->max_w ||
> +	    f->height < MIN_H || f->height > codec->max_h)
>  		return -EINVAL;
>  
>  	f->type = V4L2_FRMIVAL_TYPE_CONTINUOUS;
Philipp Zabel April 28, 2022, 8:01 a.m. UTC | #2
Hi Hans,

On Do, 2022-04-28 at 09:51 +0200, Hans Verkuil wrote:
> On 26/04/2022 11:15, Philipp Zabel wrote:
> > Let VIDIOC_ENUM_FRAMEINTERVALS return -EINVAL if userspace queries
> > frame intervals for frame sizes unsupported by the encoder. Fixes the
> > following v4l2-compliance failure:
> > 
> > 		fail: v4l2-test-formats.cpp(123): found frame intervals for invalid size 47x16
> > 		fail: v4l2-test-formats.cpp(282): node->codec_mask & STATEFUL_ENCODER
> > 	test VIDIOC_ENUM_FMT/FRAMESIZES/FRAMEINTERVALS: FAIL
> > 
> > For decoder devices, return -ENOTTY.
> 
> Shouldn't that be 'encoder devices'?
> 
> And why mention it at all since this isn't part of the changes in this patch?
> 
> I can drop this last sentence, if you like, but before I do that I need
> confirmation that that's OK.

Yes please, thank you for catching this. It is an artifact from when I
rebased this patch past a3b9b81462a2 ("media: coda: disable encoder
ioctls for decoder devices").

regards
Philipp
diff mbox series

Patch

diff --git a/drivers/media/platform/chips-media/coda-common.c b/drivers/media/platform/chips-media/coda-common.c
index 7528f2718c4d..af71eea04dbd 100644
--- a/drivers/media/platform/chips-media/coda-common.c
+++ b/drivers/media/platform/chips-media/coda-common.c
@@ -1315,7 +1315,8 @@  static int coda_enum_frameintervals(struct file *file, void *fh,
 				    struct v4l2_frmivalenum *f)
 {
 	struct coda_ctx *ctx = fh_to_ctx(fh);
-	int i;
+	struct coda_q_data *q_data;
+	const struct coda_codec *codec;
 
 	if (f->index)
 		return -EINVAL;
@@ -1324,12 +1325,19 @@  static int coda_enum_frameintervals(struct file *file, void *fh,
 	if (!ctx->vdoa && f->pixel_format == V4L2_PIX_FMT_YUYV)
 		return -EINVAL;
 
-	for (i = 0; i < CODA_MAX_FORMATS; i++) {
-		if (f->pixel_format == ctx->cvd->src_formats[i] ||
-		    f->pixel_format == ctx->cvd->dst_formats[i])
-			break;
+	if (coda_format_normalize_yuv(f->pixel_format) == V4L2_PIX_FMT_YUV420) {
+		q_data = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE);
+		codec = coda_find_codec(ctx->dev, f->pixel_format,
+					q_data->fourcc);
+	} else {
+		codec = coda_find_codec(ctx->dev, V4L2_PIX_FMT_YUV420,
+					f->pixel_format);
 	}
-	if (i == CODA_MAX_FORMATS)
+	if (!codec)
+		return -EINVAL;
+
+	if (f->width < MIN_W || f->width > codec->max_w ||
+	    f->height < MIN_H || f->height > codec->max_h)
 		return -EINVAL;
 
 	f->type = V4L2_FRMIVAL_TYPE_CONTINUOUS;