Skip to content

Commit

Permalink
media: v4l2-tpg: prevent the risk of a division by zero
Browse files Browse the repository at this point in the history
commit e6a3ea8 upstream.

As reported by Coverity, the logic at tpg_precalculate_line()
blindly rescales the buffer even when scaled_witdh is equal to
zero. If this ever happens, this will cause a division by zero.

Instead, add a WARN_ON_ONCE() to trigger such cases and return
without doing any precalculation.

Fixes: 63881df ("[media] vivid: add the Test Pattern Generator")
Cc: [email protected]
Signed-off-by: Mauro Carvalho Chehab <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
  • Loading branch information
mchehab authored and Sasha Levin committed Nov 12, 2024
1 parent 25a31f8 commit ee9a666
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions drivers/media/common/v4l2-tpg/v4l2-tpg-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -1795,6 +1795,9 @@ static void tpg_precalculate_line(struct tpg_data *tpg)
unsigned p;
unsigned x;

if (WARN_ON_ONCE(!tpg->src_width || !tpg->scaled_width))
return;

switch (tpg->pattern) {
case TPG_PAT_GREEN:
contrast = TPG_COLOR_100_RED;
Expand Down

0 comments on commit ee9a666

Please sign in to comment.