From: Niklas Söderlund Date: Mon, 14 Oct 2019 00:07:50 +0000 (-0300) Subject: media: rcar-vin: Do not enumerate unsupported pixel formats X-Git-Tag: v5.10.7~3807^2^2~88 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=8f490061747218ae3dd595637bfb6f2905e79fb7;p=platform%2Fkernel%2Flinux-rpi.git media: rcar-vin: Do not enumerate unsupported pixel formats If a pixel format is not supported by the hardware NULL is returned by rvin_format_from_pixel() for that fourcc. Verify that the pixel format is supported using this or skip it when enumerating. Signed-off-by: Niklas Söderlund Reviewed-by: Laurent Pinchart Signed-off-by: Hans Verkuil Signed-off-by: Mauro Carvalho Chehab --- diff --git a/drivers/media/platform/rcar-vin/rcar-v4l2.c b/drivers/media/platform/rcar-vin/rcar-v4l2.c index 9a9b89c..13b7cd5 100644 --- a/drivers/media/platform/rcar-vin/rcar-v4l2.c +++ b/drivers/media/platform/rcar-vin/rcar-v4l2.c @@ -296,12 +296,22 @@ static int rvin_g_fmt_vid_cap(struct file *file, void *priv, static int rvin_enum_fmt_vid_cap(struct file *file, void *priv, struct v4l2_fmtdesc *f) { - if (f->index >= ARRAY_SIZE(rvin_formats)) - return -EINVAL; - - f->pixelformat = rvin_formats[f->index].fourcc; + struct rvin_dev *vin = video_drvdata(file); + unsigned int i; + int matched; + + matched = -1; + for (i = 0; i < ARRAY_SIZE(rvin_formats); i++) { + if (rvin_format_from_pixel(vin, rvin_formats[i].fourcc)) + matched++; + + if (matched == f->index) { + f->pixelformat = rvin_formats[i].fourcc; + return 0; + } + } - return 0; + return -EINVAL; } static int rvin_g_selection(struct file *file, void *fh,