From patchwork Fri Mar 1 17:08:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mikhail Lobanov X-Patchwork-Id: 208959 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:fa17:b0:10a:f01:a869 with SMTP id ju23csp20912dyc; Fri, 1 Mar 2024 09:12:21 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUc8cBqy8MKD0MFRL/6O1Y6ChKI/bL3wiIhiRpd7NQ1WKw3GH2By76Ijq2BAdL/VeLYQmYo22y1MC1BzWhxyO4pCM3mXQ== X-Google-Smtp-Source: AGHT+IHYfLmRvewnIG8gvt2pUL0Fwe4P3X/MnhJ6d+d9djJPXxTSr+8sv49w6AIFEpLO/DAafaJA X-Received: by 2002:a0c:d790:0:b0:68f:eee3:ec32 with SMTP id z16-20020a0cd790000000b0068feee3ec32mr2120277qvi.44.1709313141618; Fri, 01 Mar 2024 09:12:21 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709313141; cv=pass; d=google.com; s=arc-20160816; b=HMav+Xp/B4lwzduJvzxCCBlWYLdaK1+H4XSuJwyG/ry3wvhRY93eUWhgNlQ0pH7UsI b3eQ4s3dQINJIkvuWoHcZH7tUaAX8NePcOFgu/XfBySN5ve1aN0FGxt2dMUv7QgaZApW GP9O4J09xC+RGpOA59v7bG+xxR4fRIW8CHpurYF5E+KZc0XwOonXPbN6zkSFYcCk9PtW b/aehen58K4ao1l3qQo1VFrid2BdQnKyybahTEQZNr5vm2vZaZTmNk1jHvs3mg7yQX8+ 9K8PkniPU73s26hGkghK3Ap3rr/yT8D4nRzO19vHj0tKASoJ5tBA6HxsdUuss7y6nc9x etcQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature:dkim-filter; bh=a6DlMHYD50bgw5c8dbRDQuJSmrsCV4dJRNHYFXyLCp8=; fh=heUQflzKV2l7WUj9SfCW1UtCklZQgaXhhfasJn/9zKs=; b=flRqwfHksCHkRQIUBFTI4RyoLu/4kAUxNXAme8aCIxTjrVkEhPVYcnPmYQD8KpE1or tStThFDI5uc8buOVJWb/Wnn3cz5xZWyXnl7FH+qQrLDK4JIvCqdCQVRDnOZ2L0Kum8uB Mlx58KbySdc0GOx17EO3hJBRsrXudzrBn7zPt3/hMErsijmYmLd+J9lkMbJj3UrocUos FX7QdjhO6btL4Ip4ovKUn8MTA2GmHrGYjz6FTAmUmb3rb6cOknKYg/lUnCdZ0CbvjOkb 0h/lAtY5o/LhVJDOcc8nOapunikwe40YU2Gs33kpz3JoW19UrU/M8rNRDI/VUMET2VYF qJ3Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@rosalinux.ru header.s=1D4BB666-A0F1-11EB-A1A2-F53579C7F503 header.b=WZJOx2BE; arc=pass (i=1 spf=pass spfdomain=rosalinux.ru dkim=pass dkdomain=rosalinux.ru dmarc=pass fromdomain=rosalinux.ru); spf=pass (google.com: domain of linux-kernel+bounces-88810-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-88810-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=rosalinux.ru Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id oo5-20020a056214450500b0068eeeabaa8fsi3782166qvb.144.2024.03.01.09.12.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 09:12:21 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-88810-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@rosalinux.ru header.s=1D4BB666-A0F1-11EB-A1A2-F53579C7F503 header.b=WZJOx2BE; arc=pass (i=1 spf=pass spfdomain=rosalinux.ru dkim=pass dkdomain=rosalinux.ru dmarc=pass fromdomain=rosalinux.ru); spf=pass (google.com: domain of linux-kernel+bounces-88810-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-88810-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=rosalinux.ru 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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 262201C2594F for ; Fri, 1 Mar 2024 17:11:27 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 21DBDF9D1; Fri, 1 Mar 2024 17:10:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rosalinux.ru header.i=@rosalinux.ru header.b="WZJOx2BE" Received: from mail.rosalinux.ru (mail.rosalinux.ru [195.19.76.54]) (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 3ED37F503; Fri, 1 Mar 2024 17:10:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.19.76.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709313045; cv=none; b=QfvR308ofjPc91HwYwSMN3PFOPSw8S57qvDSxEvuUUdKA4rjD/qLk0YuAHKzjCklXNtIPF/wZBpSfRabnk3wkQW270nrIxjWqCZFUkbtqd6aDzqOopnFiQ2Cq0eg8/4Tl5NIO2baeOQZsGiWyfWWBCWylmv1F2nu44D3mMhpw/U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709313045; c=relaxed/simple; bh=1f3lWg+pkiYMDBEYhxFCMSCS17hH2ui9obrcK7tKVE8=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=m4BHJV8ECaAS5cBzBk2LuUBv6PZPwpSF2vNsnW+pnAdlw6JT6Yv3/Ap2x25l/lPjJn6A6Ouv9IsQxCmKf7/IVeP5Ietup7S2SLLGc/RNVOIiQV5y2pJClYoe4/cNwKRpTmdodkOUgteqoSwMzdWfe8shtOAwlHDOylqqan1L+Sk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=rosalinux.ru; spf=pass smtp.mailfrom=rosalinux.ru; dkim=pass (2048-bit key) header.d=rosalinux.ru header.i=@rosalinux.ru header.b=WZJOx2BE; arc=none smtp.client-ip=195.19.76.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=rosalinux.ru Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rosalinux.ru Received: from localhost (localhost [127.0.0.1]) by mail.rosalinux.ru (Postfix) with ESMTP id B0641DD7B446E; Fri, 1 Mar 2024 20:10:29 +0300 (MSK) Received: from mail.rosalinux.ru ([127.0.0.1]) by localhost (mail.rosalinux.ru [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id 9K59O71FHrtq; Fri, 1 Mar 2024 20:10:29 +0300 (MSK) Received: from localhost (localhost [127.0.0.1]) by mail.rosalinux.ru (Postfix) with ESMTP id 7CD77DD7B4472; Fri, 1 Mar 2024 20:10:29 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.10.3 mail.rosalinux.ru 7CD77DD7B4472 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rosalinux.ru; s=1D4BB666-A0F1-11EB-A1A2-F53579C7F503; t=1709313029; bh=a6DlMHYD50bgw5c8dbRDQuJSmrsCV4dJRNHYFXyLCp8=; h=From:To:Date:Message-ID:MIME-Version; b=WZJOx2BE56ZBTHhYS4Gdw6s8fbuKRWxiG9rvR0s32OSNIiJ8FmqPE0Z9GFqpMBTxV C6OPEUJacpxpp2sgO/cCck0BPtzeX1pc/yh86Tg0Pz7tNk3/JRMwkZtnRGJU90J+iH Pyo4cdUx+fFgUYBVWbEcoFSaCuHDyyXGuxwFZmtI00G0VtefyqpImFc8sZrMyMBkbE dLsnyiXdbhVvH4fBANj+L5AzSJIkulOi5gTXysXVZ83PRsvYqGHggmQuKGibMkdGrO Bh/1VU9M9rac7U5h2ti8+QotSQOkh0LmEW30NuwEx0fuTUf9UEkHc6Lz2R6c7buGqU 9x+noiYVLTn0w== X-Virus-Scanned: amavisd-new at rosalinux.ru Received: from mail.rosalinux.ru ([127.0.0.1]) by localhost (mail.rosalinux.ru [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id 6DYsYvXOHtQm; Fri, 1 Mar 2024 20:10:29 +0300 (MSK) Received: from localhost.localdomain (unknown [62.217.186.174]) by mail.rosalinux.ru (Postfix) with ESMTPSA id 4C10ADD7B446E; Fri, 1 Mar 2024 20:10:29 +0300 (MSK) From: Mikhail Lobanov To: Mauro Carvalho Chehab Cc: Mikhail Lobanov , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] media: v4l2-tpg: Fix division by zero error in color_to_hsv Date: Fri, 1 Mar 2024 12:08:36 -0500 Message-ID: <20240301170838.57421-1-m.lobanov@rosalinux.ru> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1792344736897541839 X-GMAIL-MSGID: 1792344736897541839 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 --- 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;