All of lore.kernel.org
 help / color / mirror / Atom feed
From: Hans Verkuil <hverkuil-cisco@xs4all.nl>
To: Laurent Pinchart <laurent.pinchart@ideasonboard.com>,
	linux-media@vger.kernel.org
Cc: Sakari Ailus <sakari.ailus@iki.fi>,
	Jacopo Mondi <jacopo@jmondi.org>,
	Xavier Roumegue <xavier.roumegue@oss.nxp.com>,
	linux-imx@nxp.com, kernel@pengutronix.de
Subject: Re: [PATCH 5/7] media: v4l2: Sanitize colorspace values in the framework
Date: Wed, 29 Jun 2022 15:59:02 +0200	[thread overview]
Message-ID: <cdfc2039-42e6-e150-fdce-39eef38de15c@xs4all.nl> (raw)
In-Reply-To: <20220616183656.19089-6-laurent.pinchart@ideasonboard.com>

On 16/06/2022 20:36, Laurent Pinchart wrote:
> Extend the format sanitization code in the framework to handle invalid
> values for the colorspace-related fields.
> 
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> Acked-by: Sakari Ailus <sakari.ailus@linux.intel.com>

Reviewed-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>

Regards,

	Hans

> ---
>  drivers/media/v4l2-core/v4l2-ioctl.c | 65 +++++++++++++++++++++++-----
>  1 file changed, 55 insertions(+), 10 deletions(-)
> 
> diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
> index 18ed2227255a..24b5968e8f32 100644
> --- a/drivers/media/v4l2-core/v4l2-ioctl.c
> +++ b/drivers/media/v4l2-core/v4l2-ioctl.c
> @@ -1008,6 +1008,31 @@ static int check_fmt(struct file *file, enum v4l2_buf_type type)
>  	return -EINVAL;
>  }
>  
> +static void v4l_sanitize_colorspace(u32 pixelformat, u32 *colorspace,
> +				    u32 *encoding, u32 *quantization,
> +				    u32 *xfer_func)
> +{
> +	bool is_hsv = pixelformat == V4L2_PIX_FMT_HSV24 ||
> +		      pixelformat == V4L2_PIX_FMT_HSV32;
> +
> +	if (!v4l2_is_colorspace_valid(*colorspace)) {
> +		*colorspace = V4L2_COLORSPACE_DEFAULT;
> +		*encoding = V4L2_YCBCR_ENC_DEFAULT;
> +		*quantization = V4L2_QUANTIZATION_DEFAULT;
> +		*xfer_func = V4L2_XFER_FUNC_DEFAULT;
> +	}
> +
> +	if ((!is_hsv && !v4l2_is_ycbcr_enc_valid(*encoding)) ||
> +	    (is_hsv && !v4l2_is_hsv_enc_valid(*encoding)))
> +		*encoding = V4L2_YCBCR_ENC_DEFAULT;
> +
> +	if (!v4l2_is_quant_valid(*quantization))
> +		*quantization = V4L2_QUANTIZATION_DEFAULT;
> +
> +	if (!v4l2_is_xfer_func_valid(*xfer_func))
> +		*xfer_func = V4L2_XFER_FUNC_DEFAULT;
> +}
> +
>  static void v4l_sanitize_format(struct v4l2_format *fmt)
>  {
>  	unsigned int offset;
> @@ -1027,20 +1052,40 @@ static void v4l_sanitize_format(struct v4l2_format *fmt)
>  	 * field to the magic value when the extended pixel format structure
>  	 * isn't used by applications.
>  	 */
> +	if (fmt->type == V4L2_BUF_TYPE_VIDEO_CAPTURE ||
> +	    fmt->type == V4L2_BUF_TYPE_VIDEO_OUTPUT) {
> +		if (fmt->fmt.pix.priv != V4L2_PIX_FMT_PRIV_MAGIC) {
> +			fmt->fmt.pix.priv = V4L2_PIX_FMT_PRIV_MAGIC;
>  
> -	if (fmt->type != V4L2_BUF_TYPE_VIDEO_CAPTURE &&
> -	    fmt->type != V4L2_BUF_TYPE_VIDEO_OUTPUT)
> -		return;
> +			offset = offsetof(struct v4l2_pix_format, priv)
> +			       + sizeof(fmt->fmt.pix.priv);
> +			memset(((void *)&fmt->fmt.pix) + offset, 0,
> +			       sizeof(fmt->fmt.pix) - offset);
> +		}
> +	}
>  
> -	if (fmt->fmt.pix.priv == V4L2_PIX_FMT_PRIV_MAGIC)
> -		return;
> +	/* Replace invalid colorspace values with defaults. */
> +	if (fmt->type == V4L2_BUF_TYPE_VIDEO_CAPTURE ||
> +	    fmt->type == V4L2_BUF_TYPE_VIDEO_OUTPUT) {
> +		v4l_sanitize_colorspace(fmt->fmt.pix.pixelformat,
> +					&fmt->fmt.pix.colorspace,
> +					&fmt->fmt.pix.ycbcr_enc,
> +					&fmt->fmt.pix.quantization,
> +					&fmt->fmt.pix.xfer_func);
> +	} else if (fmt->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE ||
> +		   fmt->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) {
> +		u32 ycbcr_enc = fmt->fmt.pix_mp.ycbcr_enc;
> +		u32 quantization = fmt->fmt.pix_mp.quantization;
> +		u32 xfer_func = fmt->fmt.pix_mp.xfer_func;
>  
> -	fmt->fmt.pix.priv = V4L2_PIX_FMT_PRIV_MAGIC;
> +		v4l_sanitize_colorspace(fmt->fmt.pix_mp.pixelformat,
> +					&fmt->fmt.pix_mp.colorspace, &ycbcr_enc,
> +					&quantization, &xfer_func);
>  
> -	offset = offsetof(struct v4l2_pix_format, priv)
> -	       + sizeof(fmt->fmt.pix.priv);
> -	memset(((void *)&fmt->fmt.pix) + offset, 0,
> -	       sizeof(fmt->fmt.pix) - offset);
> +		fmt->fmt.pix_mp.ycbcr_enc = ycbcr_enc;
> +		fmt->fmt.pix_mp.quantization = quantization;
> +		fmt->fmt.pix_mp.xfer_func = xfer_func;
> +	}
>  }
>  
>  static int v4l_querycap(const struct v4l2_ioctl_ops *ops,


  reply	other threads:[~2022-06-29 13:59 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-16 18:36 [PATCH 0/7] media: nxp: i.MX8 ISI driver Laurent Pinchart
2022-06-16 18:36 ` [PATCH 1/7] media: v4l: Add packed YUV 4:4:4 YUVA and YUVX pixel formats Laurent Pinchart
2022-06-29 13:46   ` Hans Verkuil
2022-06-16 18:36 ` [PATCH 2/7] media: v4l2-tpg: Add support for the new YUVA and YUVX formats Laurent Pinchart
2022-06-28 10:22   ` Jacopo Mondi
2022-06-29 13:47   ` Hans Verkuil
2022-06-16 18:36 ` [PATCH 3/7] media: vivid: " Laurent Pinchart
2022-06-27 23:53   ` Laurent Pinchart
2022-06-28 10:28   ` Jacopo Mondi
2022-06-29 13:47   ` Hans Verkuil
2022-06-29 13:54   ` Hans Verkuil
2022-06-30  0:17     ` Laurent Pinchart
2022-06-16 18:36 ` [PATCH 4/7] media: v4l2: Make colorspace validity checks more future-proof Laurent Pinchart
2022-06-29 13:50   ` Hans Verkuil
2022-06-30  9:46     ` Sakari Ailus
2022-06-30  9:48       ` Laurent Pinchart
2022-06-30  9:56         ` Hans Verkuil
2022-06-16 18:36 ` [PATCH 5/7] media: v4l2: Sanitize colorspace values in the framework Laurent Pinchart
2022-06-29 13:59   ` Hans Verkuil [this message]
2022-06-16 18:36 ` [PATCH 6/7] dt-bindings: media: Add i.MX8 ISI DT bindings Laurent Pinchart
2022-06-17  2:47   ` Rob Herring
2022-06-16 18:36 ` [PATCH 7/7] media: nxp: Add i.MX8 ISI driver Laurent Pinchart
2022-06-17  2:40   ` kernel test robot

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=cdfc2039-42e6-e150-fdce-39eef38de15c@xs4all.nl \
    --to=hverkuil-cisco@xs4all.nl \
    --cc=jacopo@jmondi.org \
    --cc=kernel@pengutronix.de \
    --cc=laurent.pinchart@ideasonboard.com \
    --cc=linux-imx@nxp.com \
    --cc=linux-media@vger.kernel.org \
    --cc=sakari.ailus@iki.fi \
    --cc=xavier.roumegue@oss.nxp.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.