From patchwork Mon Nov 13 10:08:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alain Volmat X-Patchwork-Id: 19207 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 07440C3213 for ; Mon, 13 Nov 2023 10:09:35 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 541B5629BA; Mon, 13 Nov 2023 11:09:34 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1699870174; bh=EVFLfY2DpUKJHLC+lQ4LI9zhHvKU117OkI0DHmS5T/A=; h=To:Date:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=Zy9Dv815YwmJXDVPlY+VwBhD8do54kUe4QTDAhOcsh8V2H1KIAO+NzQQot6aIFJTU /BtEUtUBIb84Ev0geBIgfhIY/gmnEaESc/kHIIT5Rx7QdYgY0/u4nxkS2e04KKLaoK hHi5BbXQjeSwD0IYiz62oW63rGjtOWL65Yj7YXM4UzXDfw865IVP6YKriw5IUCiXjF 75E+fsmHprZ0j9IIqPkP55MFIS/un/fTj19sOvM1EEuyaWhwtqi4iOgMX7Xp+mXAif 1UFdJLOOmA3d+kgcxDB4o9X94Gl9K1Vn774EPSgXFAFM3d399zvJgWIOqKV+SzNMRd x9yadsf5OWzog== Received: from mx07-00178001.pphosted.com (mx07-00178001.pphosted.com [185.132.182.106]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 066B761DB4 for ; Mon, 13 Nov 2023 11:09:32 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=foss.st.com header.i=@foss.st.com header.b="eug3nk/F"; dkim-atps=neutral Received: from pps.filterd (m0288072.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.17.1.22/8.17.1.22) with ESMTP id 3AD91I2u021403 for ; Mon, 13 Nov 2023 11:09:31 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foss.st.com; h= from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding:content-type; s=selector1; bh=Tb4u4/w XJr6gYP+RHqyBPpapYjfVGYDq4X98JQDQqb8=; b=eug3nk/F4OY9Tan9uMnie/5 J19cp1M4kmoEPyB4acpAMLwDduDTXD8i0HOfyqMRxyepVjFi3db2YlWyePW35S15 A76l0rJ4m334uxUVBfWtH1cinig+iCYy+A0uM0hNhVyWiMi7LgGkcG67HVJGbbw2 OgxUQn+uP39qKjn/1sAclozsdEqkoaksa7U1ZQ3DhKTAbf9xktD+U+McAv271PZa ul+JKN1coMvh21c2QBtW2ED3hyhjiZ+5tMz0VltEEUbWxx6EEfR22MR1DluXtHAJ hYIJVf/DXo8bw79F/hoKqaeeNIVUp936gwr7l27xLKesq9/3r01OcqjAijky93Q= = Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com (PPS) with ESMTPS id 3u9ywkxmf7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Mon, 13 Nov 2023 11:09:31 +0100 (CET) Received: from euls16034.sgp.st.com (euls16034.sgp.st.com [10.75.44.20]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 2F36710005B for ; Mon, 13 Nov 2023 11:09:30 +0100 (CET) Received: from Webmail-eu.st.com (shfdag1node1.st.com [10.75.129.69]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id BB32221058B for ; Mon, 13 Nov 2023 11:09:30 +0100 (CET) Received: from localhost (10.129.178.213) by SHFDAG1NODE1.st.com (10.75.129.69) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Mon, 13 Nov 2023 11:09:30 +0100 To: Date: Mon, 13 Nov 2023 11:08:51 +0100 Message-ID: <20231113100851.73886-1-alain.volmat@foss.st.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Originating-IP: [10.129.178.213] X-ClientProxiedBy: SHFCAS1NODE2.st.com (10.75.129.73) To SHFDAG1NODE1.st.com (10.75.129.69) X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272, Aquarius:18.0.987, Hydra:6.0.619, FMLib:17.11.176.26 definitions=2023-11-12_24,2023-11-09_01,2023-05-22_02 Subject: [libcamera-devel] [PATCH] libcamera: camera_sensor: only access V4L_CID_HBLANK if existing X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Alain Volmat via libcamera-devel From: Alain Volmat Reply-To: Alain Volmat Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Correct a crash in CameraSensor::init when trying to set the V4L2_CID_HBLANK control on sensor not implementing this control. The HBLANK sensor not being mandatory for non-RAW sensors, it can happen that the sensor does not expose this control. Perform check against availability of the control prior to usage in order to avoid the crash. Signed-off-by: Alain Volmat Reviewed-by: Jacopo Mondi Reviewed-by: Laurent Pinchart --- src/libcamera/camera_sensor.cpp | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp index d9261672..0ef78d9c 100644 --- a/src/libcamera/camera_sensor.cpp +++ b/src/libcamera/camera_sensor.cpp @@ -197,17 +197,19 @@ int CameraSensor::init() * \todo The control API ought to have a flag to specify if a control * is read-only which could be used below. */ - const ControlInfo hblank = ctrls.infoMap()->at(V4L2_CID_HBLANK); - const int32_t hblankMin = hblank.min().get(); - const int32_t hblankMax = hblank.max().get(); - - if (hblankMin != hblankMax) { - ControlList ctrl(subdev_->controls()); - - ctrl.set(V4L2_CID_HBLANK, hblankMin); - ret = subdev_->setControls(&ctrl); - if (ret) - return ret; + if (ctrls.infoMap()->find(V4L2_CID_HBLANK) != ctrls.infoMap()->end()) { + const ControlInfo hblank = ctrls.infoMap()->at(V4L2_CID_HBLANK); + const int32_t hblankMin = hblank.min().get(); + const int32_t hblankMax = hblank.max().get(); + + if (hblankMin != hblankMax) { + ControlList ctrl(subdev_->controls()); + + ctrl.set(V4L2_CID_HBLANK, hblankMin); + ret = subdev_->setControls(&ctrl); + if (ret) + return ret; + } } return applyTestPatternMode(controls::draft::TestPatternModeEnum::TestPatternModeOff);