{"id":2634,"url":"https://patchwork.libcamera.org/api/1.1/patches/2634/?format=json","web_url":"https://patchwork.libcamera.org/patch/2634/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20200113164245.52535-20-jacopo@jmondi.org>","date":"2020-01-13T16:42:41","name":"[libcamera-devel,19/23] libcamera: controls: Validate compound controls range","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"d6daec38b15797ecb37e7f713e7de5bd9e2a2ccd","submitter":{"id":3,"url":"https://patchwork.libcamera.org/api/1.1/people/3/?format=json","name":"Jacopo Mondi","email":"jacopo@jmondi.org"},"delegate":{"id":15,"url":"https://patchwork.libcamera.org/api/1.1/users/15/?format=json","username":"jmondi","first_name":"Jacopo","last_name":"Mondi","email":"jacopo@jmondi.org"},"mbox":"https://patchwork.libcamera.org/patch/2634/mbox/","series":[{"id":618,"url":"https://patchwork.libcamera.org/api/1.1/series/618/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=618","date":"2020-01-13T16:42:22","name":"Properties and compound controls","version":1,"mbox":"https://patchwork.libcamera.org/series/618/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/2634/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/2634/checks/","tags":{},"headers":{"Return-Path":"<jacopo@jmondi.org>","Received":["from relay11.mail.gandi.net (relay11.mail.gandi.net\n\t[217.70.178.231])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 88C93606FE\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 13 Jan 2020 17:40:38 +0100 (CET)","from uno.lan (2-224-242-101.ip172.fastwebnet.it [2.224.242.101])\n\t(Authenticated sender: jacopo@jmondi.org)\n\tby relay11.mail.gandi.net (Postfix) with ESMTPSA id 259E4100005;\n\tMon, 13 Jan 2020 16:40:37 +0000 (UTC)"],"From":"Jacopo Mondi <jacopo@jmondi.org>","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","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH 19/23] libcamera: controls: Validate\n\tcompound controls range","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>","X-List-Received-Date":"Mon, 13 Jan 2020 16:40:38 -0000"},"content":"The type of a ControlRnge associated with a Control<> is different\nfrom the type of the Control<> itself if the control is a compound.\n\nAdd a function to help validation of the two types during ControlInfoMap\nidmap generation.\n\nSigned-off-by: Jacopo Mondi <jacopo@jmondi.org>\n---\n include/libcamera/controls.h |  1 +\n src/libcamera/controls.cpp   | 32 +++++++++++++++++++++++++++++++-\n 2 files changed, 32 insertions(+), 1 deletion(-)","diff":"diff --git a/include/libcamera/controls.h b/include/libcamera/controls.h\nindex 9343a947764b..a3ac2b8c5447 100644\n--- a/include/libcamera/controls.h\n+++ b/include/libcamera/controls.h\n@@ -217,6 +217,7 @@ public:\n \n private:\n \tvoid generateIdmap();\n+\tbool validateRange(const ControlId *control, const ControlRange range);\n \n \tControlIdMap idmap_;\n };\ndiff --git a/src/libcamera/controls.cpp b/src/libcamera/controls.cpp\nindex 750c36bd011e..71075ade4577 100644\n--- a/src/libcamera/controls.cpp\n+++ b/src/libcamera/controls.cpp\n@@ -940,6 +940,36 @@ ControlInfoMap::const_iterator ControlInfoMap::find(unsigned int id) const\n \treturn find(iter->second);\n }\n \n+bool ControlInfoMap::validateRange(const ControlId *control,\n+\t\t\t\t   const ControlRange range)\n+{\n+\tControlType controlType = control->type();\n+\tControlType rangeType = range.min().type();\n+\n+\t/*\n+\t * Validate the control type against its associated range type,\n+\t * regardless it being a compound control or not.\n+\t */\n+\tswitch (controlType) {\n+\tcase ControlTypeBool:\n+\tcase ControlTypeCompoundBool:\n+\t\treturn rangeType == ControlTypeBool;\n+\tcase ControlTypeInteger32:\n+\tcase ControlTypeCompoundInt32:\n+\t\treturn (rangeType == ControlTypeInteger32 ||\n+\t\t\trangeType == ControlTypeInteger64);\n+\tcase ControlTypeInteger64:\n+\tcase ControlTypeCompoundInt64:\n+\t\treturn (rangeType == ControlTypeInteger64 ||\n+\t\t\trangeType == ControlTypeInteger32);\n+\tcase ControlTypeFloat:\n+\tcase ControlTypeCompoundFloat:\n+\t\treturn rangeType == ControlTypeFloat;\n+\tdefault:\n+\t\treturn false;\n+\t}\n+}\n+\n /**\n  * \\fn const ControlIdMap &ControlInfoMap::idmap() const\n  * \\brief Retrieve the ControlId map\n@@ -956,7 +986,7 @@ void ControlInfoMap::generateIdmap()\n \tidmap_.clear();\n \n \tfor (const auto &ctrl : *this) {\n-\t\tif (ctrl.first->type() != ctrl.second.min().type()) {\n+\t\tif (!validateRange(ctrl.first, ctrl.second)) {\n \t\t\tLOG(Controls, Error)\n \t\t\t\t<< \"Control \" << utils::hex(ctrl.first->id())\n \t\t\t\t<< \" type and range type mismatch\";\n","prefixes":["libcamera-devel","19/23"]}