* [PATCH v2] rcar-vin: Do not enumerate unsupported pixel formats
@ 2019-10-14 0:07 Niklas Söderlund
2019-10-14 20:58 ` Laurent Pinchart
0 siblings, 1 reply; 2+ messages in thread
From: Niklas Söderlund @ 2019-10-14 0:07 UTC (permalink / raw)
To: Laurent Pinchart, linux-media; +Cc: linux-renesas-soc, Niklas Söderlund
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 <niklas.soderlund+renesas@ragnatech.se>
---
drivers/media/platform/rcar-vin/rcar-v4l2.c | 20 +++++++++++++++-----
1 file changed, 15 insertions(+), 5 deletions(-)
diff --git a/drivers/media/platform/rcar-vin/rcar-v4l2.c b/drivers/media/platform/rcar-vin/rcar-v4l2.c
index 9a9b89c0dc0b3be4..13b7cd5d2e40415a 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,
--
2.23.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v2] rcar-vin: Do not enumerate unsupported pixel formats
2019-10-14 0:07 [PATCH v2] rcar-vin: Do not enumerate unsupported pixel formats Niklas Söderlund
@ 2019-10-14 20:58 ` Laurent Pinchart
0 siblings, 0 replies; 2+ messages in thread
From: Laurent Pinchart @ 2019-10-14 20:58 UTC (permalink / raw)
To: Niklas Söderlund; +Cc: linux-media, linux-renesas-soc
Hi Niklas,
Thank you for the patch.
On Mon, Oct 14, 2019 at 02:07:50AM +0200, Niklas Söderlund wrote:
> 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 <niklas.soderlund+renesas@ragnatech.se>
> ---
> drivers/media/platform/rcar-vin/rcar-v4l2.c | 20 +++++++++++++++-----
> 1 file changed, 15 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/media/platform/rcar-vin/rcar-v4l2.c b/drivers/media/platform/rcar-vin/rcar-v4l2.c
> index 9a9b89c0dc0b3be4..13b7cd5d2e40415a 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;
> + }
> + }
I wonder if the following would be more readable ?
struct rvin_dev *vin = video_drvdata(file);
unsigned int index = f->index;
unsigned int i;
for (i = 0; i < ARRAY_SIZE(rvin_formats); i++) {
if (rvin_format_from_pixel(vin, rvin_formats[i].fourcc))
continue;
if (index-- == 0) {
f->pixelformat = rvin_formats[i].fourcc;
return 0;
}
}
return -EINVAL;
In any case,
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> - return 0;
> + return -EINVAL;
> }
>
> static int rvin_g_selection(struct file *file, void *fh,
--
Regards,
Laurent Pinchart
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2019-10-14 20:58 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-14 0:07 [PATCH v2] rcar-vin: Do not enumerate unsupported pixel formats Niklas Söderlund
2019-10-14 20:58 ` Laurent Pinchart
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).