linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: "Niklas Söderlund" <niklas.soderlund+renesas@ragnatech.se>
Cc: linux-media@vger.kernel.org, linux-renesas-soc@vger.kernel.org
Subject: Re: [PATCH] rcar-vin: Do not enumerate unsupported pixel formats
Date: Tue, 10 Sep 2019 02:04:41 +0300	[thread overview]
Message-ID: <20190909230441.GE15652@pendragon.ideasonboard.com> (raw)
In-Reply-To: <20190906143500.21882-1-niklas.soderlund+renesas@ragnatech.se>

Hi Niklas,

Thank you for the patch.

On Fri, Sep 06, 2019 at 04:35:00PM +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 | 12 +++++++++++-
>  1 file changed, 11 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/media/platform/rcar-vin/rcar-v4l2.c b/drivers/media/platform/rcar-vin/rcar-v4l2.c
> index cbc1c07f0a9631a4..ba08f6c49956e899 100644
> --- a/drivers/media/platform/rcar-vin/rcar-v4l2.c
> +++ b/drivers/media/platform/rcar-vin/rcar-v4l2.c
> @@ -302,10 +302,20 @@ 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)
>  {
> +	struct rvin_dev *vin = video_drvdata(file);
> +	unsigned int i, skip = 0;

This doesn't seem right. Let's consider, as initial conditions,

rvin_formats = { RGB, unsupported, unsupported, YUV }
ARRAY_SIZE(rvin_formats) == 4
f->index = 1

You want to return YUV.

> +
>  	if (f->index >= ARRAY_SIZE(rvin_formats))
>  		return -EINVAL;

This check will pass.

> -	f->pixelformat = rvin_formats[f->index].fourcc;
> +	for (i = 0; i <= f->index; i++)
> +		if (!rvin_format_from_pixel(vin, rvin_formats[i].fourcc))
> +			skip++;

This loop will have two iterations, i == 0 and i == 1. The second
iteration will increase skip, so skip == 1.

> +
> +	if (f->index + skip >= ARRAY_SIZE(rvin_formats))
> +		return -EINVAL;

This check will pass.

> +
> +	f->pixelformat = rvin_formats[f->index + skip].fourcc;

This will return unsupported format.

>  
>  	return 0;
>  }

-- 
Regards,

Laurent Pinchart

      reply	other threads:[~2019-09-09 23:04 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-06 14:35 [PATCH] rcar-vin: Do not enumerate unsupported pixel formats Niklas Söderlund
2019-09-09 23:04 ` Laurent Pinchart [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190909230441.GE15652@pendragon.ideasonboard.com \
    --to=laurent.pinchart@ideasonboard.com \
    --cc=linux-media@vger.kernel.org \
    --cc=linux-renesas-soc@vger.kernel.org \
    --cc=niklas.soderlund+renesas@ragnatech.se \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).