Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4172a34e authored by Philipp Zabel's avatar Philipp Zabel Committed by Greg Kroah-Hartman
Browse files

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



[ Upstream commit 67e33dd957880879e785cfea83a3aa24bd5c5577 ]

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

[hverkuil: drop incorrect 'For decoder devices, return -ENOTTY.' in the commit log]

Signed-off-by: default avatarPhilipp Zabel <p.zabel@pengutronix.de>
Signed-off-by: default avatarHans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@kernel.org>
Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
parent 8f2a5721
Loading
Loading
Loading
Loading
+14 −6
Original line number Diff line number Diff line
@@ -1192,7 +1192,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;
@@ -1201,12 +1202,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;