Skip to content

Commit 1c017ef

Browse files
Denny-Lingregkh
authored andcommitted
media: tegra-video: vi: fix invalid u32 return value in format lookup
commit d5b5005 upstream. 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. Returning 0 is not a valid fourcc either. This condition should never happen, so use WARN_ON_ONCE() to catch unexpected out-of-bounds access and return a valid fallback format instead. Suggested-by: Hans Verkuil <hverkuil+cisco@kernel.org> Fixes: 3d8a97e ("media: tegra-video: Add Tegra210 Video input driver") Cc: stable@vger.kernel.org Reviewed-by: Luca Ceresoli <luca.ceresoli@bootlin.com> Signed-off-by: Hungyu Lin <dennylin0707@gmail.com> Signed-off-by: Hans Verkuil <hverkuil+cisco@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent a8abecc commit 1c017ef

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

  • drivers/staging/media/tegra-video

drivers/staging/media/tegra-video/vi.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ static int tegra_get_format_idx_by_code(struct tegra_vi *vi,
8080
static u32 tegra_get_format_fourcc_by_idx(struct tegra_vi *vi,
8181
unsigned int index)
8282
{
83-
if (index >= vi->soc->nformats)
84-
return -EINVAL;
83+
if (WARN_ON_ONCE(index >= vi->soc->nformats))
84+
return vi->soc->video_formats[0].fourcc;
8585

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

0 commit comments

Comments
 (0)