[PATCH 1/2] staging: media: tegra-video: fix wrong return type in tegra_get_format_fourcc_by_idx()
From: Alexandru Hossu
Date: Sat Apr 11 2026 - 17:11:47 EST
The function is declared to return u32, but returns -EINVAL on the error
path. Due to implicit conversion, -EINVAL (-22) becomes 0xFFFFFFEA as u32,
which is an invalid V4L2 pixel format value.
The caller tegra_channel_enum_format() assigns this garbage value directly
to f->pixelformat and returns 0 (success) to userspace via VIDIOC_ENUM_FMT,
giving applications a silently wrong format descriptor instead of an error.
Fix this by changing the return type to int and propagating the error
correctly in the caller.
Signed-off-by: Alexandru Hossu <hossu.alexandru@xxxxxxxxx>
---
drivers/staging/media/tegra-video/vi.c | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
diff --git a/drivers/staging/media/tegra-video/vi.c b/drivers/staging/media/tegra-video/vi.c
index 9c0b38585d63..afc7327ef318 100644
--- a/drivers/staging/media/tegra-video/vi.c
+++ b/drivers/staging/media/tegra-video/vi.c
@@ -77,13 +77,13 @@ static int tegra_get_format_idx_by_code(struct tegra_vi *vi,
return -1;
}
-static u32 tegra_get_format_fourcc_by_idx(struct tegra_vi *vi,
+static int tegra_get_format_fourcc_by_idx(struct tegra_vi *vi,
unsigned int index)
{
if (index >= vi->soc->nformats)
return -EINVAL;
- return vi->soc->video_formats[index].fourcc;
+ return (int)vi->soc->video_formats[index].fourcc;
}
static const struct tegra_video_format *
@@ -395,6 +395,7 @@ static int tegra_channel_enum_format(struct file *file, void *fh,
struct tegra_vi_channel *chan = video_drvdata(file);
unsigned int index = 0, i;
unsigned long *fmts_bitmap = chan->tpg_fmts_bitmap;
+ int ret;
if (!IS_ENABLED(CONFIG_VIDEO_TEGRA_TPG))
fmts_bitmap = chan->fmts_bitmap;
@@ -405,7 +406,11 @@ static int tegra_channel_enum_format(struct file *file, void *fh,
for (i = 0; i < f->index + 1; i++, index++)
index = find_next_bit(fmts_bitmap, MAX_FORMAT_NUM, index);
- f->pixelformat = tegra_get_format_fourcc_by_idx(chan->vi, index - 1);
+ ret = tegra_get_format_fourcc_by_idx(chan->vi, index - 1);
+ if (ret < 0)
+ return ret;
+
+ f->pixelformat = ret;
return 0;
}
--
2.53.0