Skip to content

Commit e6a3ea8

Browse files
committed
media: v4l2-tpg: prevent the risk of a division by zero
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: stable@vger.kernel.org Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
1 parent 4c76f33 commit e6a3ea8

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

drivers/media/common/v4l2-tpg/v4l2-tpg-core.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1795,6 +1795,9 @@ static void tpg_precalculate_line(struct tpg_data *tpg)
17951795
unsigned p;
17961796
unsigned x;
17971797

1798+
if (WARN_ON_ONCE(!tpg->src_width || !tpg->scaled_width))
1799+
return;
1800+
17981801
switch (tpg->pattern) {
17991802
case TPG_PAT_GREEN:
18001803
contrast = TPG_COLOR_100_RED;

0 commit comments

Comments
 (0)