From patchwork Mon Jan 13 16:42:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 2634 X-Patchwork-Delegate: jacopo@jmondi.org Return-Path: Received: from relay11.mail.gandi.net (relay11.mail.gandi.net [217.70.178.231]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 88C93606FE for ; Mon, 13 Jan 2020 17:40:38 +0100 (CET) Received: from uno.lan (2-224-242-101.ip172.fastwebnet.it [2.224.242.101]) (Authenticated sender: jacopo@jmondi.org) by relay11.mail.gandi.net (Postfix) with ESMTPSA id 259E4100005; Mon, 13 Jan 2020 16:40:37 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Mon, 13 Jan 2020 17:42:41 +0100 Message-Id: <20200113164245.52535-20-jacopo@jmondi.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20200113164245.52535-1-jacopo@jmondi.org> References: <20200113164245.52535-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 19/23] libcamera: controls: Validate compound controls range 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-List-Received-Date: Mon, 13 Jan 2020 16:40:38 -0000 The type of a ControlRnge associated with a Control<> is different from the type of the Control<> itself if the control is a compound. Add a function to help validation of the two types during ControlInfoMap idmap generation. Signed-off-by: Jacopo Mondi --- include/libcamera/controls.h | 1 + src/libcamera/controls.cpp | 32 +++++++++++++++++++++++++++++++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/include/libcamera/controls.h b/include/libcamera/controls.h index 9343a947764b..a3ac2b8c5447 100644 --- a/include/libcamera/controls.h +++ b/include/libcamera/controls.h @@ -217,6 +217,7 @@ public: private: void generateIdmap(); + bool validateRange(const ControlId *control, const ControlRange range); ControlIdMap idmap_; }; diff --git a/src/libcamera/controls.cpp b/src/libcamera/controls.cpp index 750c36bd011e..71075ade4577 100644 --- a/src/libcamera/controls.cpp +++ b/src/libcamera/controls.cpp @@ -940,6 +940,36 @@ ControlInfoMap::const_iterator ControlInfoMap::find(unsigned int id) const return find(iter->second); } +bool ControlInfoMap::validateRange(const ControlId *control, + const ControlRange range) +{ + ControlType controlType = control->type(); + ControlType rangeType = range.min().type(); + + /* + * Validate the control type against its associated range type, + * regardless it being a compound control or not. + */ + switch (controlType) { + case ControlTypeBool: + case ControlTypeCompoundBool: + return rangeType == ControlTypeBool; + case ControlTypeInteger32: + case ControlTypeCompoundInt32: + return (rangeType == ControlTypeInteger32 || + rangeType == ControlTypeInteger64); + case ControlTypeInteger64: + case ControlTypeCompoundInt64: + return (rangeType == ControlTypeInteger64 || + rangeType == ControlTypeInteger32); + case ControlTypeFloat: + case ControlTypeCompoundFloat: + return rangeType == ControlTypeFloat; + default: + return false; + } +} + /** * \fn const ControlIdMap &ControlInfoMap::idmap() const * \brief Retrieve the ControlId map @@ -956,7 +986,7 @@ void ControlInfoMap::generateIdmap() idmap_.clear(); for (const auto &ctrl : *this) { - if (ctrl.first->type() != ctrl.second.min().type()) { + if (!validateRange(ctrl.first, ctrl.second)) { LOG(Controls, Error) << "Control " << utils::hex(ctrl.first->id()) << " type and range type mismatch";