Re: [PATCH] media: tegra-video: vi: fix invalid u32 return value in format lookup

From: Hans Verkuil

Date: Wed May 06 2026 - 03:02:14 EST


On 12/04/2026 02:02, Hungyu Lin wrote:
> tegra_get_format_fourcc_by_idx() returns a u32 but uses -EINVAL
> to signal an out-of-bounds index. This results in a large unsigned
> value being returned, which may be interpreted as a valid fourcc.
>
> Return 0 instead to indicate an invalid format.
>
> Callers assign the return value directly to pixelformat, so returning
> an error code encoded in u32 is unsafe.
>
> Signed-off-by: Hungyu Lin <dennylin0707@xxxxxxxxx>
> ---
> drivers/staging/media/tegra-video/vi.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/staging/media/tegra-video/vi.c b/drivers/staging/media/tegra-video/vi.c
> index 9c0b38585d63..966792a6ec19 100644
> --- a/drivers/staging/media/tegra-video/vi.c
> +++ b/drivers/staging/media/tegra-video/vi.c
> @@ -81,7 +81,7 @@ static u32 tegra_get_format_fourcc_by_idx(struct tegra_vi *vi,
> unsigned int index)
> {
> if (index >= vi->soc->nformats)
> - return -EINVAL;
> + return 0;

Returning 0 is not a valid fourcc either.

This should never happen, so use WARN_ON_ONCE in the 'if' and return
vi->soc->video_formats[0].fourcc;

That's at least better than the current code.

Regards,

Hans

>
> return vi->soc->video_formats[index].fourcc;
> }