[v2,1/2] media: rockchip: rkcif: Filter enumerated formats by media bus code
diff mbox series

Message ID 20261118203134.315591-2-faizel.kb@gmail.com
State New
Headers show
Series
  • media: rockchip: rkcif: ENUM_FMT and bytesperline fixes
Related show

Commit Message

Faizel K B Nov. 18, 2026, 8:31 p.m. UTC
VIDIOC_ENUM_FMT ignores the mbus_code field and returns all formats,
although the video devices set V4L2_CAP_IO_MC. Return only the formats
that match the requested media bus code. The DVP output formats have no
media bus code, so they are still all returned.

Otherwise userspace can pick a pixel format that doesn't match the
media bus format, and then interprets the captured data in the wrong
format.

Signed-off-by: Faizel K B <faizel.kb@gmail.com>
---
 .../platform/rockchip/rkcif/rkcif-stream.c     | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)

Patch
diff mbox series

diff --git a/drivers/media/platform/rockchip/rkcif/rkcif-stream.c b/drivers/media/platform/rockchip/rkcif/rkcif-stream.c
index 3130d420ad55..b117ba57bc75 100644
--- a/drivers/media/platform/rockchip/rkcif/rkcif-stream.c
+++ b/drivers/media/platform/rockchip/rkcif/rkcif-stream.c
@@ -395,13 +395,23 @@  static int rkcif_stream_enum_formats(struct file *file, void *priv,
 				     struct v4l2_fmtdesc *f)
 {
 	struct rkcif_stream *stream = video_drvdata(file);
+	const struct rkcif_output_fmt *fmt;
+	unsigned int i, n = 0;
 
-	if (f->index >= stream->out_fmts_num)
-		return -EINVAL;
+	for (i = 0; i < stream->out_fmts_num; i++) {
+		fmt = &stream->out_fmts[i];
 
-	f->pixelformat = stream->out_fmts[f->index].fourcc;
+		if (f->mbus_code && fmt->mbus_code &&
+		    fmt->mbus_code != f->mbus_code)
+			continue;
 
-	return 0;
+		if (n++ == f->index) {
+			f->pixelformat = fmt->fourcc;
+			return 0;
+		}
+	}
+
+	return -EINVAL;
 }
 
 static int rkcif_stream_enum_framesizes(struct file *file, void *fh,