Received: by 2002:ab2:3350:0:b0:1f4:6588:b3a7 with SMTP id o16csp1217136lqe; Mon, 8 Apr 2024 02:13:46 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWeiKOus26kaSzyWzwuvxh/xqJVR3hb7b8/5nbDR30Rc8OBwzEy1DM1Inj+OOKWN+tQrjWVSLhUNJSVBAdnFJRFjZ8C82LGkw7huQBd5Q== X-Google-Smtp-Source: AGHT+IGHbhZvmOkED82vJl67PBd02HgOK1fVrivCnGtV4os4rzoUl7d9AURLUSG6sDvUP/DWNCI3 X-Received: by 2002:a05:6a00:180e:b0:6ea:b1f5:112b with SMTP id y14-20020a056a00180e00b006eab1f5112bmr10595520pfa.21.1712567626379; Mon, 08 Apr 2024 02:13:46 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712567626; cv=pass; d=google.com; s=arc-20160816; b=Z3KfRhgC25f0mmuPgaM04eMbjiLE+Yw9sA1ZKG3FLfCsx5ptwuxWvsrj88IdPTcOuQ H/tOlgxZWLX5a0/sG2qqntXkycfhOa5Ua//PlPmMo3RvE4VW/Ng/1lXhpxIfslG/20uk c0e+ZvKCKRFF/g4MyvVYVIjJmWt7HL5EKkZ8rXLk6V5S1j0ng04EI5xw2P5eWHawNuAc wSy9a+hwy8XQSQJlEYoDgCAwEACJEVi/+tXMawZjjfNG0PC9zGcJzaxDfd3rDtvawelm hsW7bKgi9GhVwNNYOAVQsUFSZJs6xf4MoHkKO89gWp0QZ2r8/YAZ0XIVa1KE8xFH3khl RYwQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:autocrypt:from:references:cc :to:content-language:subject:user-agent:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:date:message-id; bh=SNbm2lied6PDfvavR+pM3KFDXsv/AqIAmkx8PE8mlpU=; fh=CxIlwCd41EotwLqWyY6oG46BHFV32xFrzs89/mEZUuU=; b=V3El+itBgRojr6KKLIfFJLAv+sLoxu1UeewIAKiPIQzvUkgAaGN5lfPjsFqqqy0G4y BlQkdNiNx9GwlJVR6TWzn+LxeWYEFS5+kZp+o537FnYOhqT4kJmdi8DhUx3u+lxklhS1 3hPZbQRtma9dmcHyR2ZGvzVUf7zL84Mx19YdmSIBHAx6os9GgJeAJp4AjG4j3aCwrU12 LIOuO3bLe2SA20M2dBDJsK1wT7eaLs5pnuJOGRBEePIV0Qgq+xfZ/mLHoU3lN6cenliI lFNXAoqp4ZKACJKp0UVrPCSbt5VwGpE89TeK6VSBhi9MVT43VMvvEdg38/IATAk3zYSk ZaHQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-135114-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-135114-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=xs4all.nl Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id k7-20020aa788c7000000b006ed21ce7c39si2695130pff.251.2024.04.08.02.13.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Apr 2024 02:13:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-135114-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-135114-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-135114-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=xs4all.nl Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id F19A0283FC9 for ; Mon, 8 Apr 2024 09:13:45 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BF4404086F; Mon, 8 Apr 2024 09:13:37 +0000 (UTC) Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3FCFC34CDE; Mon, 8 Apr 2024 09:13:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712567617; cv=none; b=ToV+d1F6kFmFC9jKQLWn+khNuUeCV9I+dUI6xNJu2IOTL1M2i4JOuzUrUV/IAja9UYoO0GGuyoJOJepuPymVsodwHrjbfxnZtJiUy7AzsqwfIb5F2OmSqHA+V4/PjL9sjJ830eQ0Z1puyGf1LMQWofa2ZsRythOfB6P17wyZj40= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712567617; c=relaxed/simple; bh=yTqsvhBCkSc78Imgw8E+ZDntOPJsWlkyEET4fsR9Q6k=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=OBZRGBS3HCuXUGTq6fzhbI8OJUMjuNh3O4L+8aD47HGgZY1WTM/FBR8o4QbQATYi4d2h8j6pptUfdJ9b6M55bVtVwrT2aKxzKG/ew4n19QG5kIKHTyByRx4jysUQefj8yM/kOxAD/1MoerJSOAN1DKEXkhfyjdi7x0/qYKfttZc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 10ED0C433C7; Mon, 8 Apr 2024 09:13:35 +0000 (UTC) Message-ID: Date: Mon, 8 Apr 2024 11:13:34 +0200 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] media: v4l2-tpg: Fix division by zero error in color_to_hsv Content-Language: en-US, nl To: Mikhail Lobanov , Mauro Carvalho Chehab Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org References: <20240301170838.57421-1-m.lobanov@rosalinux.ru> From: Hans Verkuil Autocrypt: addr=hverkuil@xs4all.nl; keydata= xsFNBFQ84W0BEAC7EF1iL4s3tY8cRTVkJT/297h0Hz0ypA+ByVM4CdU9sN6ua/YoFlr9k0K4 BFUlg7JzJoUuRbKxkYb8mmqOe722j7N3HO8+ofnio5cAP5W0WwDpM0kM84BeHU0aPSTsWiGR yw55SOK2JBSq7hueotWLfJLobMWhQii0Zd83hGT9SIt9uHaHjgwmtTH7MSTIiaY6N14nw2Ud C6Uykc1va0Wqqc2ov5ihgk/2k2SKa02ookQI3e79laOrbZl5BOXNKR9LguuOZdX4XYR3Zi6/ BsJ7pVCK9xkiVf8svlEl94IHb+sa1KrlgGv3fn5xgzDw8Z222TfFceDL/2EzUyTdWc4GaPMC E/c1B4UOle6ZHg02+I8tZicjzj5+yffv1lB5A1btG+AmoZrgf0X2O1B96fqgHx8w9PIpVERN YsmkfxvhfP3MO3oHh8UY1OLKdlKamMneCLk2up1Zlli347KMjHAVjBAiy8qOguKF9k7HOjif JCLYTkggrRiEiE1xg4tblBNj8WGyKH+u/hwwwBqCd/Px2HvhAsJQ7DwuuB3vBAp845BJYUU3 06kRihFqbO0vEt4QmcQDcbWINeZ2zX5TK7QQ91ldHdqJn6MhXulPKcM8tCkdD8YNXXKyKqNl UVqXnarz8m2JCbHgjEkUlAJCNd6m3pfESLZwSWsLYL49R5yxIwARAQABzSFIYW5zIFZlcmt1 aWwgPGh2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tndxR0SFat sflovhDxKyhFwXOP0Rv8H378/+14TaykknRBIKEc0+lcr+EMOSUR5eg4aURb8Gc3Uc7fgQ6q UssTXzHPyj1hAyDpfu8DzAwlh4kKFTodxSsKAjI45SLjadSc94/5Gy8645Y1KgBzBPTH7Q== In-Reply-To: <20240301170838.57421-1-m.lobanov@rosalinux.ru> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 01/03/2024 18:08, Mikhail Lobanov wrote: > 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 With this patch I get this compiler warning: drivers/media/common/v4l2-tpg/v4l2-tpg-core.c: In function 'precalculate_color': drivers/media/common/v4l2-tpg/v4l2-tpg-core.c:1004:35: warning: 'h' may be used uninitialized [-Wmaybe-uninitialized] 1004 | tpg->colors[k][0] = h; | ~~~~~~~~~~~~~~~~~~^~~ drivers/media/common/v4l2-tpg/v4l2-tpg-core.c:1001:21: note: 'h' was declared here 1001 | int h, s, v; | ^ In any case, I think this patch is wrong. Based on this formula: https://www.rapidtables.com/convert/color/rgb-to-hsv.html The bug is in: *s = aux; if (!aux) { *h = 0; return; } 'if (!aux)' should be 'if (!diff_rgb)'. Regards, Hans > --- > 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;