[PATCH v9 1/4] media: v4l2-ctrls: validate AV1 reference frame index

Nicolas Dufresne nicolas.dufresne at collabora.com
Thu Nov 26 18:03:06 PST 2026


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 at collabora.com>

Reviewed-by: Nicolas Dufresne <nicolas.dufresne at 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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 228 bytes
Desc: This is a digitally signed message part
URL: <http://lists.infradead.org/pipermail/linux-rockchip/attachments/20261126/d5d402a4/attachment.sig>


More information about the Linux-rockchip mailing list