Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: 63881df94d3e ("[media] vivid: add the Test Pattern Generator")
Cc: stable@vger.kernel.org
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>

+3
+3
drivers/media/common/v4l2-tpg/v4l2-tpg-core.c
··· 1795 1795 unsigned p; 1796 1796 unsigned x; 1797 1797 1798 + if (WARN_ON_ONCE(!tpg->src_width || !tpg->scaled_width)) 1799 + return; 1800 + 1798 1801 switch (tpg->pattern) { 1799 1802 case TPG_PAT_GREEN: 1800 1803 contrast = TPG_COLOR_100_RED;