Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1E482C433F5 for ; Wed, 12 Jan 2022 09:03:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238265AbiALJDJ (ORCPT ); Wed, 12 Jan 2022 04:03:09 -0500 Received: from relay6-d.mail.gandi.net ([217.70.183.198]:57557 "EHLO relay6-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238082AbiALJDH (ORCPT ); Wed, 12 Jan 2022 04:03:07 -0500 Received: (Authenticated sender: jacopo@jmondi.org) by relay6-d.mail.gandi.net (Postfix) with ESMTPSA id A05B7C000A; Wed, 12 Jan 2022 09:03:04 +0000 (UTC) Date: Wed, 12 Jan 2022 10:04:05 +0100 From: Jacopo Mondi To: Eugen Hristev Cc: linux-media@vger.kernel.org, robh+dt@kernel.org, laurent.pinchart@ideasonboard.com, sakari.ailus@iki.fi, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, nicolas.ferre@microchip.com Subject: Re: [PATCH v3 19/23] media: atmel: atmel-isc-base: clamp wb gain coefficients Message-ID: <20220112090405.tjgz47dhdbyjrwxr@uno.localdomain> References: <20211213134940.324266-1-eugen.hristev@microchip.com> <20211213134940.324266-20-eugen.hristev@microchip.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20211213134940.324266-20-eugen.hristev@microchip.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Eugen On Mon, Dec 13, 2021 at 03:49:36PM +0200, Eugen Hristev wrote: > White balance computed gains can overflow above the 13 bits hardware > coefficient that can be used, in some specific scenarios like a subexposure > from the sensor when the image is mostly black. > In this case the computed gain has to be clamped to the maximum value > allowed by the hardware. > > Signed-off-by: Eugen Hristev > --- > drivers/media/platform/atmel/atmel-isc-base.c | 4 ++++ > 1 file changed, 4 insertions(+) > > diff --git a/drivers/media/platform/atmel/atmel-isc-base.c b/drivers/media/platform/atmel/atmel-isc-base.c > index f1f1019f9d82..31c8e3029eee 100644 > --- a/drivers/media/platform/atmel/atmel-isc-base.c > +++ b/drivers/media/platform/atmel/atmel-isc-base.c > @@ -1415,6 +1415,10 @@ static void isc_wb_update(struct isc_ctrls *ctrls) > /* multiply both gains and adjust for decimals */ > ctrls->gain[c] = s_gain[c] * gw_gain[c]; > ctrls->gain[c] >>= 9; > + > + /* make sure we are not out of range */ > + ctrls->gain[c] = clamp_val(ctrls->gain[c], 0, GENMASK(12, 0)); #include What is the type of gain[c} ? If it's unsigned clamping with [0 is not required. I would in that case gain[c] = min(gain[c], ...) It's fine anyway Reviewed-by: Jacopo Mondi Thanks j > + > v4l2_dbg(1, debug, &isc->v4l2_dev, > "isc wb: component %d, final gain %u\n", > c, ctrls->gain[c]); > -- > 2.25.1 >