diff options
author | Mauro Carvalho Chehab <mchehab+huawei@kernel.org> | 2024-10-16 11:53:15 +0200 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab+huawei@kernel.org> | 2024-10-18 10:43:03 +0200 |
commit | e6a3ea83fbe15d4818d01804e904cbb0e64e543b (patch) | |
tree | 35b6f63a63684df5b7779dcc991d4a2c49ed469d | |
parent | 4c76f331a9a173ac8fe1297a9231c2a38f88e368 (diff) | |
download | linux-stable-e6a3ea83fbe15d4818d01804e904cbb0e64e543b.tar.gz linux-stable-e6a3ea83fbe15d4818d01804e904cbb0e64e543b.tar.bz2 linux-stable-e6a3ea83fbe15d4818d01804e904cbb0e64e543b.zip |
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>
-rw-r--r-- | drivers/media/common/v4l2-tpg/v4l2-tpg-core.c | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/drivers/media/common/v4l2-tpg/v4l2-tpg-core.c b/drivers/media/common/v4l2-tpg/v4l2-tpg-core.c index 642c48e8c1f5..ded11cd8dbf7 100644 --- a/drivers/media/common/v4l2-tpg/v4l2-tpg-core.c +++ b/drivers/media/common/v4l2-tpg/v4l2-tpg-core.c @@ -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; |