[PATCH] media: v4l2-tpg: Fix division by zero error in color_to_hsv

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxx>
---
 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





[Index of Archives]     [Linux Input]     [Video for Linux]     [Gstreamer Embedded]     [Mplayer Users]     [Linux USB Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]

  Powered by Linux