[PATCH v3 04/17] media: v4l2-ctrls: validate av1 tile info

Nicolas Dufresne nicolas at ndufresne.ca
Tue Nov 24 14:12:51 PST 2026


Le mardi 20 octobre 2026 à 11:37 +0200, Sofus Forstreuter a écrit :
> Many drivers use tile_cols and/or tile_rows, so make sure they are
> valid.
> 
> Increase V4L2_AV1_MAX_TILE_COUNT to MAX_TILE_COLS * MAX_TILE_ROWS
> 
> Reviewed-by: Neal Gompa <neal at gompa.dev>
> Signed-off-by: Sofus Forstreuter <sofus.c at icloud.com>
> ---
>  drivers/media/v4l2-core/v4l2-ctrls-core.c | 15 +++++++++++++++
>  include/uapi/linux/v4l2-controls.h        |  2 +-
>  2 files changed, 16 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/media/v4l2-core/v4l2-ctrls-core.c b/drivers/media/v4l2-core/v4l2-ctrls-core.c
> index 661a3a25da52..922cf74c4eb8 100644
> --- a/drivers/media/v4l2-core/v4l2-ctrls-core.c
> +++ b/drivers/media/v4l2-core/v4l2-ctrls-core.c
> @@ -800,10 +800,25 @@ static int validate_av1_film_grain(struct v4l2_ctrl_av1_film_grain *fg)
>  	return 0;
>  }
>  
> +static int validate_av1_tile_info(struct v4l2_av1_tile_info *ti)
> +{
> +	if (ti->tile_cols > V4L2_AV1_MAX_TILE_COLS ||
> +	    ti->tile_rows > V4L2_AV1_MAX_TILE_ROWS)
> +		return -EINVAL;
> +
> +	if (ti->context_update_tile_id >= ti->tile_cols * ti->tile_rows)
> +		return -EINVAL;

Make sure to update std_init_compound() so that the default passes the check
please.

> +
> +	return 0;
> +}
> +
>  static int validate_av1_frame(struct v4l2_ctrl_av1_frame *f)
>  {
>  	int ret = 0;
>  
> +	ret = validate_av1_tile_info(&f->tile_info);
> +	if (ret)
> +		return ret;
>  	ret = validate_av1_quantization(&f->quantization);
>  	if (ret)
>  		return ret;
> diff --git a/include/uapi/linux/v4l2-controls.h b/include/uapi/linux/v4l2-controls.h
> index d17e41d51d2e..abdfa102a77b 100644
> --- a/include/uapi/linux/v4l2-controls.h
> +++ b/include/uapi/linux/v4l2-controls.h
> @@ -2939,7 +2939,7 @@ struct v4l2_ctrl_vp9_compressed_hdr {
>  #define V4L2_AV1_MAX_NUM_PLANES		3
>  #define V4L2_AV1_MAX_TILE_COLS		64
>  #define V4L2_AV1_MAX_TILE_ROWS		64
> -#define V4L2_AV1_MAX_TILE_COUNT		512
> +#define V4L2_AV1_MAX_TILE_COUNT		4096

Hmm, added Daniel in CC, no idea how we ended up with 512 here. This will
increase MTK insance size, but the communication with the firmware seems
dynamic.

Hantro is limited to 128 and properly reject anything above. So in all, should
be fine, unless there is a problem with MTK firmware, which which case I'd
suggest to program the original limit in there. Also added Xiaoyong in CC.

>  
>  #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/20261124/01fabe39/attachment-0001.sig>


More information about the Linux-rockchip mailing list