Re: [PATCH] media: tegra-video: vi: validate format index before bitmap_set

From: Dan Carpenter

Date: Mon Apr 13 2026 - 03:56:46 EST


On Sun, Apr 12, 2026 at 03:48:43PM +0000, Hungyu Lin wrote:
> tegra_get_format_idx_by_code() returns -1 when no matching format
> is found. vi_tpg_fmts_bitmap_init() used the returned index directly
> in bitmap_set(), which may lead to an out-of-bounds access when the
> format is not present.
>
> This can occur when TPG is enabled on SoCs whose video_formats[]
> table does not include the requested media bus formats.
>
> Validate the index before calling bitmap_set().
>
> Signed-off-by: Hungyu Lin <dennylin0707@xxxxxxxxx>
> ---

This isn't a bug which can occur in real life since the index is
always found... If there were really a bug, like say someone were
writing a new driver and messed up, then this would just paper over
the issue and make the bug harder to find, so in a way it makes the
code worse.

regards,
dan carpenter