mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Nicolas Dufresne <nicolas.dufresne@collabora.com>
To: Benjamin Gaignard <benjamin.gaignard@collabora.com>,
	 p.zabel@pengutronix.de, mchehab@kernel.org, heiko@sntech.de,
	hverkuil@kernel.org
Cc: linux-kernel@vger.kernel.org, linux-media@vger.kernel.org,
	 linux-rockchip@lists.infradead.org,
	linux-arm-kernel@lists.infradead.org,  kernel@collabora.com
Subject: Re: [PATCH v9 1/4] media: v4l2-ctrls: validate AV1 reference frame index
Date: Thu, 26 Nov 2026 21:03:06 -0500	[thread overview]
Message-ID: <747f8cf069d6e49b6eec3313d590b144d6e710fd.camel@collabora.com> (raw)
In-Reply-To: <20261125122825.236422-2-benjamin.gaignard@collabora.com>

[-- Attachment #1: Type: text/plain, Size: 2993 bytes --]

Le mercredi 25 novembre 2026 à 13:28 +0100, Benjamin Gaignard a écrit :
> The stateless AV1 decoders use primary_ref_frame and ref_frame_idx[] to
> to find the matching reference frames.
> V4L2_AV1_PRIMARY_REF_NONE is the value of primary_ref_frame indicating
> that there is no primary reference frame.
> Iterate over ref_frame_idx[] to check if the indexes are in [-1, 7] range
> like described in AV1 specifications.
> 
> Signed-off-by: Benjamin Gaignard <benjamin.gaignard@collabora.com>

Reviewed-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>

> ---
> changes in v9:
> - Split core changes and drivers changes
> - Add V4L2_AV1_REF_FRAME_INVALID
> - Rework checks in validate_av1_reference_index() to be sure that
>   all values of ref_frame_idx[] are in the correct range.
> 
>  drivers/media/v4l2-core/v4l2-ctrls-core.c | 30 +++++++++++++++++++++++
>  include/uapi/linux/v4l2-controls.h        |  2 ++
>  2 files changed, 32 insertions(+)
> 
> diff --git a/drivers/media/v4l2-core/v4l2-ctrls-core.c b/drivers/media/v4l2-core/v4l2-ctrls-core.c
> index 6e751a043a21..e707897e36fd 100644
> --- a/drivers/media/v4l2-core/v4l2-ctrls-core.c
> +++ b/drivers/media/v4l2-core/v4l2-ctrls-core.c
> @@ -817,10 +817,40 @@ static int validate_av1_tile_info(struct v4l2_av1_tile_info *t)
>  	return 0;
>  }
>  
> +static int validate_av1_reference_index(struct v4l2_ctrl_av1_frame *f)
> +{
> +	int i, idx;
> +
> +	/* The valid range for ref_frame_idx[] values is [-1, 7] */
> +	for (i = 0; i < V4L2_AV1_REFS_PER_FRAME; i++) {
> +		idx = f->ref_frame_idx[i];
> +		if (idx < V4L2_AV1_REF_FRAME_INVALID)
> +			return -EINVAL;
> +		if (idx >= V4L2_AV1_TOTAL_REFS_PER_FRAME)
> +			return -EINVAL;
> +	}
> +
> +	if (f->primary_ref_frame > V4L2_AV1_PRIMARY_REF_NONE)
> +		return -EINVAL;
> +
> +	if (f->primary_ref_frame == V4L2_AV1_PRIMARY_REF_NONE)
> +		return 0;
> +
> +	/* If set primary_ref_frame index must be valid */
> +	idx = f->ref_frame_idx[f->primary_ref_frame];
> +	if (idx <= V4L2_AV1_REF_FRAME_INVALID)
> +		return -EINVAL;
> +
> +	return 0;
> +}
> +
>  static int validate_av1_frame(struct v4l2_ctrl_av1_frame *f)
>  {
>  	int ret = 0;
>  
> +	ret = validate_av1_reference_index(f);
> +	if (ret)
> +		return ret;
>  	ret = validate_av1_tile_info(&f->tile_info);
>  	if (ret)
>  		return ret;
> diff --git a/include/uapi/linux/v4l2-controls.h b/include/uapi/linux/v4l2-controls.h
> index d17e41d51d2e..f21f00fd5a84 100644
> --- a/include/uapi/linux/v4l2-controls.h
> +++ b/include/uapi/linux/v4l2-controls.h
> @@ -2940,6 +2940,8 @@ struct v4l2_ctrl_vp9_compressed_hdr {
>  #define V4L2_AV1_MAX_TILE_COLS		64
>  #define V4L2_AV1_MAX_TILE_ROWS		64
>  #define V4L2_AV1_MAX_TILE_COUNT		512
> +#define V4L2_AV1_PRIMARY_REF_NONE	7
> +#define V4L2_AV1_REF_FRAME_INVALID	-1
>  
>  #define V4L2_AV1_SEQUENCE_FLAG_STILL_PICTURE		  0x00000001
>  #define V4L2_AV1_SEQUENCE_FLAG_USE_128X128_SUPERBLOCK	  0x00000002

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

  reply	other threads:[~2026-11-27  2:03 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-25 12:28 [PATCH v9 0/4] media: verisilicon: Create AV1 helper library Benjamin Gaignard
2026-11-25 12:28 ` [PATCH v9 1/4] media: v4l2-ctrls: validate AV1 reference frame index Benjamin Gaignard
2026-11-27  2:03   ` Nicolas Dufresne [this message]
2026-11-25 12:28 ` [PATCH v9 2/4] media: verisilicon: Use V4L2_AV1_PRIMARY_REF_NONE and V4L2_AV1_REF_FRAME_INVALID Benjamin Gaignard
2026-11-27  2:03   ` Nicolas Dufresne
2026-11-25 12:28 ` [PATCH v9 3/4] media: verisilicon: AV1: Fix luma size Benjamin Gaignard
2026-11-25 12:28 ` [PATCH v9 4/4] media: verisilicon: Create AV1 helper library Benjamin Gaignard

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=747f8cf069d6e49b6eec3313d590b144d6e710fd.camel@collabora.com \
    --to=nicolas.dufresne@collabora.com \
    --cc=benjamin.gaignard@collabora.com \
    --cc=heiko@sntech.de \
    --cc=hverkuil@kernel.org \
    --cc=kernel@collabora.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=linux-rockchip@lists.infradead.org \
    --cc=mchehab@kernel.org \
    --cc=p.zabel@pengutronix.de \
    /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

all inboxes | Powered by JetHome®