[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20240301170838.57421-1-m.lobanov@rosalinux.ru>
Date: Fri, 1 Mar 2024 12:08:36 -0500
From: Mikhail Lobanov <m.lobanov@...alinux.ru>
To: Mauro Carvalho Chehab <mchehab@...nel.org>
Cc: Mikhail Lobanov <m.lobanov@...alinux.ru>,
linux-media@...r.kernel.org,
linux-kernel@...r.kernel.org
Subject: [PATCH] media: v4l2-tpg: Fix division by zero error in color_to_hsv
In the color_to_hsv function, division by zero is possible due to
attributes r,g,b are equal so diff_rgb = 0.
Found by Linux Verification Center (linuxtesting.org) with SVACE.
Fixes: 54fb15348385 ("[media] vivid: Add support for HSV formats")
Signed-off-by: Mikhail Lobanov <m.lobanov@...alinux.ru>
---
drivers/media/common/v4l2-tpg/v4l2-tpg-core.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/drivers/media/common/v4l2-tpg/v4l2-tpg-core.c b/drivers/media/common/v4l2-tpg/v4l2-tpg-core.c
index a366566f22c3..943aab3ad97c 100644
--- a/drivers/media/common/v4l2-tpg/v4l2-tpg-core.c
+++ b/drivers/media/common/v4l2-tpg/v4l2-tpg-core.c
@@ -597,6 +597,11 @@ static void color_to_hsv(struct tpg_data *tpg, int r, int g, int b,
third = third_size * 2;
}
+ if (!diff_rgb) {
+ *s = 0;
+ return;
+ }
+
aux *= third_size / 2;
aux += diff_rgb / 2;
aux /= diff_rgb;
--
2.39.2
Powered by blists - more mailing lists