Skip to contentSkip to conversation

media: tegra-video: vi: fix invalid u32 return value in format lookup

PATCH In review Hungyu Lin 2 participants 4 messages May 7

Subsystems (5)
lore
Share & tools
lore

Hungyu Lin

author
#0 lore raw

v3 cover media: tegra-video: vi: fix invalid u32 return value in format lookup

Changes in v3:
- Add Fixes tag and Cc: [email protected] as suggested by Luca Ceresoli.
- Add Reviewed-by: Luca Ceresoli.

Changes in v2:
- Follow Hans Verkuil's suggestion to use WARN_ON_ONCE() and return the first available format (index 0) as a safe fallback.

Hungyu Lin (1):
media: tegra-video: vi: fix invalid u32 return value in format lookup

 drivers/staging/media/tegra-video/vi.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Signature · 1 line
2.34.1
author
#1 lore raw

PATCH v3 1/1 media: tegra-video: vi: fix invalid u32 return value in format lookup

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.

Fixes 3d8a97eabef0 ("media: tegra-video: Add Tegra210 Video input driver")
---
 drivers/staging/media/tegra-video/vi.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/staging/media/tegra-video/vi.c +2 -2
index f14cdc7b5211..456134a9e8cf 100644
@@ -80,8 +80,8 @@ static int tegra_get_format_idx_by_code(struct tegra_vi *vi,
 static u32 tegra_get_format_fourcc_by_idx(struct tegra_vi *vi,
 					  unsigned int index)
 {
-	if (index >= vi->soc->nformats)
-		return -EINVAL;
+	if (WARN_ON_ONCE(index >= vi->soc->nformats))
+		return vi->soc->video_formats[0].fourcc;
 
 	return vi->soc->video_formats[index].fourcc;
 }
Signature · 1 line
2.34.1
author
#2 lore raw

Hi,

The media CI reports a missing Signed-off-by from Ricardo Ribalda, but this patch was submitted directly by me and has not been handled by any committer yet.

I believe this is a false positive.

Could you please confirm?

Thanks,
Hungyu

Quoted 36 lines · Hungyu Lin

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.

Fixes 3d8a97eabef0 ("media: tegra-video: Add Tegra210 Video input driver")
---
 drivers/staging/media/tegra-video/vi.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/staging/media/tegra-video/vi.c +2 -3
index f14cdc7b5211..456134a9e8cf 100644
@@ -80,8 +80,8 @@ static int tegra_get_format_idx_by_code(struct tegra_vi *vi,
 static u32 tegra_get_format_fourcc_by_idx(struct tegra_vi *vi,
                                          unsigned int index)
 {
-       if (index >= vi->soc->nformats)
-               return -EINVAL;
+       if (WARN_ON_ONCE(index >= vi->soc->nformats))
+               return vi->soc->video_formats[0].fourcc;
 
        return vi->soc->video_formats[index].fourcc;
 }
--

2.34.1

#3 lore raw

Hi Denny

Quoted 8 lines · Denny Lin

Hi,

The media CI reports a missing Signed-off-by from Ricardo Ribalda, but this patch was submitted directly by me and has not been handled by any committer yet.

I believe this is a false positive.

It is indeed a false positive. Sorry about that

Regards!

Quoted 44 lines

Could you please confirm?

Thanks,
Hungyu

Quoted 36 lines · Hungyu Lin

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.

Fixes 3d8a97eabef0 ("media: tegra-video: Add Tegra210 Video input driver")
---
 drivers/staging/media/tegra-video/vi.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/staging/media/tegra-video/vi.c +2 -3
index f14cdc7b5211..456134a9e8cf 100644
@@ -80,8 +80,8 @@ static int tegra_get_format_idx_by_code(struct tegra_vi *vi,
 static u32 tegra_get_format_fourcc_by_idx(struct tegra_vi *vi,
                                          unsigned int index)
 {
-       if (index >= vi->soc->nformats)
-               return -EINVAL;
+       if (WARN_ON_ONCE(index >= vi->soc->nformats))
+               return vi->soc->video_formats[0].fourcc;
 
        return vi->soc->video_formats[index].fourcc;
 }
--

2.34.1

Signature · 1 line
Ricardo Ribalda