Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp1454661pxb; Fri, 22 Oct 2021 00:58:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxehPQwbVgs46lMa+dTSDmg0mpxsFa3vaeCmFM2oEocIiATu+oz2ZOQsGmiZ/z/Ll/bcKpf X-Received: by 2002:a17:902:a710:b029:12b:9b9f:c461 with SMTP id w16-20020a170902a710b029012b9b9fc461mr10021024plq.59.1634889532703; Fri, 22 Oct 2021 00:58:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634889532; cv=none; d=google.com; s=arc-20160816; b=hu10RnUD2CmMVAnjd6EV5QWPVFNNMc8MCfWEberW7/102ARRJSAg4PNexOSdCGkh9k JljbOg2B5ZExsbnitHQOLTYBRQ9xPCpQAk77hUdOp7vW2LYCPAd/QlVNYlgBNriV+NIb e0blAMv3YHhorgczoOobcj5wEXls8UB/nKrKVUtkyCAcoU3IJRN9vtu58ALa3RyM7xJA 7innjsQLmdS3edDO6LQai/jW3bgpcabBR7KZcfrdXdIOyZl/ATSsFuq3wRz4JuiabMER I3A1HSjMwRteme/H+zbaxe/nnqgHIxoMMQ4uegSnter56C4sRZ03SYpQO/GZjaFtJtV8 ZPdg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :ironport-sdr:dkim-signature; bh=ls4gDNQXweNlyc7aDBV2hLoULGlhHSLm7rdQ25+Hn+o=; b=pffC5D5u1GCKzJMgWrNje+Yere2kY5COa6xtLZH1Tp8KoJO1KuB2M6D80ogm0h1y08 Agh3UDCX+D0RpkGOPRDhT+G6JoSrmOCprjWt9GWkvps5if91tja3yfz7mjNLYekp4TPV 0t9i0yo7p64HNkNv+PVBY1DTF6WA+58Ub0SINuKhq8mECv9jM7P8CNYOXWSNJggRg3EP Hf9jglZ0p+cvSrK3/Dbyb18gRM7i9u+FK9DvYOC8kHrVlsGJmH4Q21nrtQXe0yurm7Th 1YmGjs/ch2lX6sIj2PMRapZzNiM6rOZDKKm6V41ZEBp5HOYXg3MliBrYx9JXjSsCf2Vy x03Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@microchip.com header.s=mchp header.b=WNKYFIsX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=microchip.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f10si10976067pfj.200.2021.10.22.00.58.38; Fri, 22 Oct 2021 00:58:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=fail header.i=@microchip.com header.s=mchp header.b=WNKYFIsX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=microchip.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232554AbhJVH5o (ORCPT + 99 others); Fri, 22 Oct 2021 03:57:44 -0400 Received: from esa.microchip.iphmx.com ([68.232.154.123]:17502 "EHLO esa.microchip.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232601AbhJVH5U (ORCPT ); Fri, 22 Oct 2021 03:57:20 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1634889303; x=1666425303; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=wDcAUxy4+J7U+nbdqT4H/qC13HwZeJ4M+KkOlbGfiME=; b=WNKYFIsX6oeMYEYqqdpd7eX4+WsBGHcvme8EvBUy0b8BtnB7EAG5teWn Q53mNfWvjlvrMIihHz/ol9OFp9vJ1Wy7aZImxLKnNDizBT32c8vw434ff vLsZVpv1R95P3ZSH2lT0FMnjF/2PmZ4PiK4GqrRZqtzbvkJ40jFXSMXzM 9JA+qnk3+4KtpO7PDaJ8D9mncGy7KuzE+puWnEVJkJ01m8rZmv7hKbroZ f6KNXN6MQFUbPHSZ0YDItxurG5zrcmi6ikNerOfVJ9MV3CVobLj6DQb4V ZaSpjzvi3jGAyLzYc3NS8PPAN+0tTxIqtNSmzyxYEzNu0ONM7pf7pw9SZ Q==; IronPort-SDR: pQHfuea1n6HvBzLnXY4q2xY5gL5e2sVLtU/XkIjxJXH5IWwVumJOUTKrqIA4G48+f0LYa3v0/N j1O+74QXzZ4BWFHn7fdcWoQBndpZAWNvdleLQwWVktbIRErYMkB3chhmeQGT5oYpk/z8rTXr34 ea5j/qt0GGRdHGZ1j51UXtf9Tmx8kG/30/qqSYLzUN9J+GsKvpv4idcEKe6Z7I9wXNWCD3+LOm T4sR+Y5gjQtpi2VNltRGTo3dp5mFWf0zSyDe9Mh63RxHnW4Kuzni2G/Bj45jdqYTG/POrBDRst c/pzKP+Rd+GTzkMdKxxqGoVD X-IronPort-AV: E=Sophos;i="5.87,172,1631602800"; d="scan'208";a="136538173" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa2.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 22 Oct 2021 00:55:02 -0700 Received: from chn-vm-ex02.mchp-main.com (10.10.85.144) by chn-vm-ex03.mchp-main.com (10.10.85.151) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.14; Fri, 22 Oct 2021 00:55:02 -0700 Received: from ROB-ULT-M18282.microchip.com (10.10.115.15) by chn-vm-ex02.mchp-main.com (10.10.85.144) with Microsoft SMTP Server id 15.1.2176.14 via Frontend Transport; Fri, 22 Oct 2021 00:54:58 -0700 From: Eugen Hristev To: , , , CC: , , , , , Eugen Hristev Subject: [PATCH 21/21] media: atmel: atmel-isc-base: clamp wb gain coefficients Date: Fri, 22 Oct 2021 10:52:47 +0300 Message-ID: <20211022075247.518880-22-eugen.hristev@microchip.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211022075247.518880-1-eugen.hristev@microchip.com> References: <20211022075247.518880-1-eugen.hristev@microchip.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 071ac5eec7ec..53141de78f67 100644 --- a/drivers/media/platform/atmel/atmel-isc-base.c +++ b/drivers/media/platform/atmel/atmel-isc-base.c @@ -1416,6 +1416,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)); + v4l2_dbg(1, debug, &isc->v4l2_dev, "isc wb: component %d, final gain %u\n", c, ctrls->gain[c]); -- 2.25.1