[{"id":36036,"web_url":"https://patchwork.libcamera.org/comment/36036/","msgid":"<d3a6ba56-63e5-4516-9240-7789840d1c17@kernel.org>","date":"2025-09-29T11:39:52","subject":"Re: [PATCH v4 7/7] ipa: simple: agc: Prevent division by zero in AGC","submitter":{"id":239,"url":"https://patchwork.libcamera.org/api/people/239/","name":"Hans de Goede","email":"hansg@kernel.org"},"content":"Hi,\n\nOn 25-Sep-25 21:28, Milan Zamazal wrote:\n> If the histogram size is non-zero but lower than the number of bins,\n> yHistValsPerBin is zero and then the AGC processing crashes on division\n> by it.  Let's check yHistValsPerBin for being zero and stop AGC\n> processing in such a case.  The condition also covers the cases where\n> histogramSize or yHistValsPerBinMod are zero.\n> \n> Tested-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>\n> Signed-off-by: Milan Zamazal <mzamazal@redhat.com>\n\nThanks, patch looks good to me:\n\nReviewed-by: Hans de Goede <hansg@kernel.org>\n\nRegards,\n\nHans\n\n\n> ---\n>  src/ipa/simple/algorithms/agc.cpp | 6 ++++++\n>  1 file changed, 6 insertions(+)\n> \n> diff --git a/src/ipa/simple/algorithms/agc.cpp b/src/ipa/simple/algorithms/agc.cpp\n> index c46bb0ebe..e47949ec4 100644\n> --- a/src/ipa/simple/algorithms/agc.cpp\n> +++ b/src/ipa/simple/algorithms/agc.cpp\n> @@ -124,6 +124,12 @@ void Agc::process(IPAContext &context,\n>  \tunsigned int denom = 0;\n>  \tunsigned int num = 0;\n>  \n> +\tif (yHistValsPerBin == 0) {\n> +\t\tLOG(IPASoftExposure, Debug)\n> +\t\t\t<< \"Not adjusting exposure due to insufficient histogram data\";\n> +\t\treturn;\n> +\t}\n> +\n>  \tfor (unsigned int i = 0; i < histogramSize; i++) {\n>  \t\tunsigned int idx = (i - (i / yHistValsPerBinMod)) / yHistValsPerBin;\n>  \t\texposureBins[idx] += histogram[blackLevelHistIdx + i];","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 5AA55C328C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 29 Sep 2025 11:40:00 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 2B97D6B5F8;\n\tMon, 29 Sep 2025 13:39:59 +0200 (CEST)","from tor.source.kernel.org (tor.source.kernel.org\n\t[IPv6:2600:3c04:e001:324:0:1991:8:25])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 225456B599\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 29 Sep 2025 13:39:57 +0200 (CEST)","from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58])\n\tby tor.source.kernel.org (Postfix) with ESMTP id 1DE8F6245E;\n\tMon, 29 Sep 2025 11:39:56 +0000 (UTC)","by smtp.kernel.org (Postfix) with ESMTPSA id 936EAC4CEF4;\n\tMon, 29 Sep 2025 11:39:54 +0000 (UTC)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key;\n\tunprotected) header.d=kernel.org header.i=@kernel.org\n\theader.b=\"qYQHzIhk\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org;\n\ts=k20201202; t=1759145995;\n\tbh=qgT3R5SUU7bzzFjBAGJsvYH259tDC9+HnUWh/naGcjs=;\n\th=Date:Subject:To:Cc:References:From:In-Reply-To:From;\n\tb=qYQHzIhk6rtPiXmXT/ybynoM9mgMkEzP2CHyc7aI7ALFiAadS8LZKDhebfSPDB7g6\n\tML9Ntuzx6ZVnZk4Yj/L/OUfbzLEqXGUiRepa+vU5ph9VEw1qMvMnWuB8hzEKTyF8//\n\tAXkKXIIxNPl/KaMwYM+5NQKLFlw7nIZo3AafQH47niOJguGJjsSERrPIJFhlS7plKL\n\tgT0/QHdaj0IkenMKIf1XjI7riq2cjnBju7gO8D23fvpqbRNIBDpRAPa79PXeX+p7vz\n\tEc6/QZFuoOuwr6ppudv8bLo+j/KSFXJJSmrenZCOkE/cis9wQgocbF5d8uF/vAMxBE\n\tnJ3TqjAyodtMw==","Message-ID":"<d3a6ba56-63e5-4516-9240-7789840d1c17@kernel.org>","Date":"Mon, 29 Sep 2025 13:39:52 +0200","MIME-Version":"1.0","User-Agent":"Mozilla Thunderbird","Subject":"Re: [PATCH v4 7/7] ipa: simple: agc: Prevent division by zero in AGC","To":"Milan Zamazal <mzamazal@redhat.com>, libcamera-devel@lists.libcamera.org","Cc":"pobrn@protonmail.com, mail@maciej.szmigiero.name, =?utf-8?q?Barnab?=\n\t=?utf-8?b?w6FzIFDFkWN6ZQ==?= <barnabas.pocze@ideasonboard.com>","References":"<20250925192856.77881-1-mzamazal@redhat.com>\n\t<20250925192856.77881-8-mzamazal@redhat.com>","From":"Hans de Goede <hansg@kernel.org>","Content-Language":"en-US, nl","In-Reply-To":"<20250925192856.77881-8-mzamazal@redhat.com>","Content-Type":"text/plain; charset=UTF-8","Content-Transfer-Encoding":"8bit","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]