From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: "Niklas Söderlund" <niklas.soderlund+renesas@ragnatech.se>
Cc: Mauro Carvalho Chehab <mchehab@kernel.org>,
Hans Verkuil <hans.verkuil@cisco.com>,
linux-media@vger.kernel.org, linux-renesas-soc@vger.kernel.org
Subject: Re: [PATCH] videodev2.h: add helper to validate colorspace
Date: Wed, 14 Feb 2018 00:23:05 +0200 [thread overview]
Message-ID: <2862017.uVaJOSAbcn@avalon> (raw)
In-Reply-To: <20180213220847.10856-1-niklas.soderlund+renesas@ragnatech.se>
Hi Niklas,
Thank you for the patch.
On Wednesday, 14 February 2018 00:08:47 EET Niklas Söderlund wrote:
> There is no way for drivers to validate a colorspace value, which could
> be provided by user-space by VIDIOC_S_FMT for example. Add a helper to
> validate that the colorspace value is part of enum v4l2_colorspace.
>
> Signed-off-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
> ---
> include/uapi/linux/videodev2.h | 5 +++++
> 1 file changed, 5 insertions(+)
>
> Hi,
>
> I hope this is the correct header to add this helper to. I think it's
> since if it's in uapi not only can v4l2 drivers use it but tools like
> v4l-compliance gets access to it and can be updated to use this instead
> of the hard-coded check of just < 0xff as it was last time I checked.
>
> // Niklas
>
> diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
> index 9827189651801e12..843afd7c5b000553 100644
> --- a/include/uapi/linux/videodev2.h
> +++ b/include/uapi/linux/videodev2.h
> @@ -238,6 +238,11 @@ enum v4l2_colorspace {
> V4L2_COLORSPACE_DCI_P3 = 12,
> };
>
> +/* Determine if a colorspace is defined in enum v4l2_colorspace */
> +#define V4L2_COLORSPACE_IS_VALID(colorspace) \
> + (((colorspace) >= V4L2_COLORSPACE_DEFAULT) && \
> + ((colorspace) <= V4L2_COLORSPACE_DCI_P3))
> +
This looks pretty good to me. I'd remove the parentheses around each test
though.
One potential issue is that if this macro operates on an unsigned value (for
instance an u32, which is the type used for the colorspace field in various
structures) the compiler will generate a warning:
enum.c: In function ‘test_4’:
enum.c:30:16: warning: comparison of unsigned expression >= 0 is always true
[-Wtype-limits]
return V4L2_COLORSPACE_IS_VALID(colorspace);
Dropping the first check would fix that, but wouldn't catch invalid values
when operating on a signed type, such as int or enum v4l2_colorspace.
> /*
> * Determine how COLORSPACE_DEFAULT should map to a proper colorspace.
> * This depends on whether this is a SDTV image (use SMPTE 170M), an
--
Regards,
Laurent Pinchart
next prev parent reply other threads:[~2018-02-13 22:22 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-02-13 22:08 [PATCH] videodev2.h: add helper to validate colorspace Niklas Söderlund
2018-02-13 22:23 ` Laurent Pinchart [this message]
2018-02-13 22:52 ` Sakari Ailus
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=2862017.uVaJOSAbcn@avalon \
--to=laurent.pinchart@ideasonboard.com \
--cc=hans.verkuil@cisco.com \
--cc=linux-media@vger.kernel.org \
--cc=linux-renesas-soc@vger.kernel.org \
--cc=mchehab@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