[{"id":22451,"web_url":"https://patchwork.libcamera.org/comment/22451/","msgid":"<164820893730.1341993.2360852856251400278@Monstersaurus>","date":"2022-03-25T11:48:57","subject":"Re: [libcamera-devel] [PATCH v4 3/3] ipa: ipu3: Ensure controls\n\texists in before they are queried","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Quoting Umang Jain via libcamera-devel (2022-03-25 10:34:10)\n> Add a validation check for sensor controls validateSensorControls()\n> before they are queried in IPAIPU3::updateSessionConfiguration().\n> Fail the IPAIPU3::configure() if the required sensor controls are\n> not found.\n> \n> Signed-off-by: Umang Jain <umang.jain@ideasonboard.com>\n> ---\n>  src/ipa/ipu3/ipu3.cpp | 28 ++++++++++++++++++++++++++++\n>  1 file changed, 28 insertions(+)\n> \n> diff --git a/src/ipa/ipu3/ipu3.cpp b/src/ipa/ipu3/ipu3.cpp\n> index 3717d893..50b52d8b 100644\n> --- a/src/ipa/ipu3/ipu3.cpp\n> +++ b/src/ipa/ipu3/ipu3.cpp\n> @@ -155,6 +155,7 @@ private:\n>         void parseStatistics(unsigned int frame,\n>                              int64_t frameTimestamp,\n>                              const ipu3_uapi_stats_3a *stats);\n> +       bool validateSensorControls();\n>  \n>         void setControls(unsigned int frame);\n>         void calculateBdsGrid(const Size &bdsOutputSize);\n> @@ -268,6 +269,28 @@ void IPAIPU3::updateControls(const IPACameraSensorInfo &sensorInfo,\n>         *ipaControls = ControlInfoMap(std::move(controls), controls::controls);\n>  }\n>  \n> +/**\n> + * \\brief Validate that the sensor controls mandatory for the IPA exists\n> + */\n> +bool IPAIPU3::validateSensorControls()\n> +{\n> +       static const uint32_t ctrls[] = {\n> +               V4L2_CID_ANALOGUE_GAIN,\n> +               V4L2_CID_EXPOSURE,\n> +               V4L2_CID_VBLANK,\n> +       };\n> +\n> +       for (auto c : ctrls) {\n> +               if (sensorCtrls_.find(c) == sensorCtrls_.end()) {\n> +                       LOG(IPAIPU3, Error) << \"Unable to find sensor control \"\n> +                                           << utils::hex(c);\n> +                       return false;\n> +               }\n> +       }\n> +\n> +       return true;\n> +}\n> +\n>  /**\n>   * \\brief Initialize the IPA module and its controls\n>   *\n> @@ -433,6 +456,11 @@ int IPAIPU3::configure(const IPAConfigInfo &configInfo,\n>         /* Clean frameContext at each reconfiguration. */\n>         context_.frameContext = {};\n>  \n> +       if (!validateSensorControls()) {\n> +               LOG(IPAIPU3, Error) << \"Sensor control validation failed.\";\n> +               return -EINVAL;\n> +       }\n> +\n\nI think this is fine, but I would have probably put it directly after\nthe assignment of\n\n\tsensorCtrls_ = configInfo.sensorControls;\n\nin IPAIPU3::configure().\n\nOr better yet, if IPAIPU3::validateSensorControls() takes a reference to\na control list, we can validate the configInfo.sensorControls; before we\nassign it? That way we're logically validating the input before we\naccept it.\n\n\nEither way though - it's not a big deal, so:\n\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\n\n>         /* Update the camera controls using the new sensor settings. */\n>         updateControls(sensorInfo_, sensorCtrls_, ipaControls);\n>  \n> -- \n> 2.31.1\n>","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id CFD4FBD80A\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 25 Mar 2022 11:49:02 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 39287604C4;\n\tFri, 25 Mar 2022 12:49:02 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 27ADC601F8\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 25 Mar 2022 12:49:00 +0100 (CET)","from pendragon.ideasonboard.com\n\t(cpc89244-aztw30-2-0-cust3082.18-1.cable.virginm.net [86.31.172.11])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id BCE1B59E;\n\tFri, 25 Mar 2022 12:48:59 +0100 (CET)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1648208942;\n\tbh=PnHe7bnxhZ2WBs79qW78wfr7LLcJYlk9jdC9EFD5gfk=;\n\th=In-Reply-To:References:To:Date:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:\n\tFrom;\n\tb=U8SS56hNfiBW1j0O2oRJqgDWdSmLr2bFgydXhb6GmIwFsqezttdXQJKP5tCbZ4Ayb\n\t5aqso/kWAeKw745uDbigVAIS3wYlhal8VwhDWNGmplYeaXYXyxukdtbu6gdpt5EY8x\n\tM5aovfsrzDxsJHAwWpbhi/7hcxPZZ692ba2hNEKbWNusOQfUuvXrvj2w0jNp3j0sJn\n\tNWDP1uKNsv+iGg78SfmtSUzaoWWhRGJc110M3tZRWQYVyQsWwtdg2twPx7fY3pQ4yJ\n\ta0qtRRFVAJgP07qvUQ3u4A0hOKJS0DvJQTXkyOtJcPIH+KgY4CwlJHFaMdY3edzMlS\n\tAAvXmhuezzByw==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1648208939;\n\tbh=PnHe7bnxhZ2WBs79qW78wfr7LLcJYlk9jdC9EFD5gfk=;\n\th=In-Reply-To:References:Subject:From:To:Date:From;\n\tb=jI4HGY/i8mTQAfexw+b17uD7g4IUmt1aiWI00fNoYrdU8gIlOsyFYZej76jQzcung\n\thBjRsxBTh+tlGeM3WJho+NqlorM1XMmcgkW/q78cw/16f7Y3d/uyDmlX6YUEYSxfxd\n\ty+LYFWEXq/InGb4wdN3f3Sc0pN4m1quM5saGk7qM="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"jI4HGY/i\"; dkim-atps=neutral","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20220325103410.38580-4-umang.jain@ideasonboard.com>","References":"<20220325103410.38580-1-umang.jain@ideasonboard.com>\n\t<20220325103410.38580-4-umang.jain@ideasonboard.com>","To":"Umang Jain <umang.jain@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","Date":"Fri, 25 Mar 2022 11:48:57 +0000","Message-ID":"<164820893730.1341993.2360852856251400278@Monstersaurus>","User-Agent":"alot/0.10","Subject":"Re: [libcamera-devel] [PATCH v4 3/3] ipa: ipu3: Ensure controls\n\texists in before they are queried","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>","From":"Kieran Bingham via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>","Reply-To":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":22466,"web_url":"https://patchwork.libcamera.org/comment/22466/","msgid":"<YkDXDC238H/dPdPl@pendragon.ideasonboard.com>","date":"2022-03-27T21:28:44","subject":"Re: [libcamera-devel] [PATCH v4 3/3] ipa: ipu3: Ensure controls\n\texists in before they are queried","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"On Fri, Mar 25, 2022 at 11:48:57AM +0000, Kieran Bingham via libcamera-devel wrote:\n> Quoting Umang Jain via libcamera-devel (2022-03-25 10:34:10)\n> > Add a validation check for sensor controls validateSensorControls()\n> > before they are queried in IPAIPU3::updateSessionConfiguration().\n> > Fail the IPAIPU3::configure() if the required sensor controls are\n> > not found.\n> > \n> > Signed-off-by: Umang Jain <umang.jain@ideasonboard.com>\n> > ---\n> >  src/ipa/ipu3/ipu3.cpp | 28 ++++++++++++++++++++++++++++\n> >  1 file changed, 28 insertions(+)\n> > \n> > diff --git a/src/ipa/ipu3/ipu3.cpp b/src/ipa/ipu3/ipu3.cpp\n> > index 3717d893..50b52d8b 100644\n> > --- a/src/ipa/ipu3/ipu3.cpp\n> > +++ b/src/ipa/ipu3/ipu3.cpp\n> > @@ -155,6 +155,7 @@ private:\n> >         void parseStatistics(unsigned int frame,\n> >                              int64_t frameTimestamp,\n> >                              const ipu3_uapi_stats_3a *stats);\n> > +       bool validateSensorControls();\n> >  \n> >         void setControls(unsigned int frame);\n> >         void calculateBdsGrid(const Size &bdsOutputSize);\n> > @@ -268,6 +269,28 @@ void IPAIPU3::updateControls(const IPACameraSensorInfo &sensorInfo,\n> >         *ipaControls = ControlInfoMap(std::move(controls), controls::controls);\n> >  }\n> >  \n> > +/**\n> > + * \\brief Validate that the sensor controls mandatory for the IPA exists\n> > + */\n> > +bool IPAIPU3::validateSensorControls()\n> > +{\n> > +       static const uint32_t ctrls[] = {\n> > +               V4L2_CID_ANALOGUE_GAIN,\n> > +               V4L2_CID_EXPOSURE,\n> > +               V4L2_CID_VBLANK,\n> > +       };\n> > +\n> > +       for (auto c : ctrls) {\n> > +               if (sensorCtrls_.find(c) == sensorCtrls_.end()) {\n> > +                       LOG(IPAIPU3, Error) << \"Unable to find sensor control \"\n> > +                                           << utils::hex(c);\n> > +                       return false;\n> > +               }\n> > +       }\n> > +\n> > +       return true;\n> > +}\n> > +\n> >  /**\n> >   * \\brief Initialize the IPA module and its controls\n> >   *\n> > @@ -433,6 +456,11 @@ int IPAIPU3::configure(const IPAConfigInfo &configInfo,\n> >         /* Clean frameContext at each reconfiguration. */\n> >         context_.frameContext = {};\n> >  \n> > +       if (!validateSensorControls()) {\n> > +               LOG(IPAIPU3, Error) << \"Sensor control validation failed.\";\n> > +               return -EINVAL;\n> > +       }\n> > +\n> \n> I think this is fine, but I would have probably put it directly after\n> the assignment of\n> \n> \tsensorCtrls_ = configInfo.sensorControls;\n> \n> in IPAIPU3::configure().\n> \n> Or better yet, if IPAIPU3::validateSensorControls() takes a reference to\n> a control list, we can validate the configInfo.sensorControls; before we\n> assign it? That way we're logically validating the input before we\n> accept it.\n\nI like that.\n\n> Either way though - it's not a big deal, so:\n> \n> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\nLikewise,\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n> >         /* Update the camera controls using the new sensor settings. */\n> >         updateControls(sensorInfo_, sensorCtrls_, ipaControls);\n> >","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 4557AC0F1B\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSun, 27 Mar 2022 21:28:49 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 8030965631;\n\tSun, 27 Mar 2022 23:28:48 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 034DD600AB\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSun, 27 Mar 2022 23:28:46 +0200 (CEST)","from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi\n\t[62.78.145.57])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 627FD2F7;\n\tSun, 27 Mar 2022 23:28:46 +0200 (CEST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1648416528;\n\tbh=XE0DymOSOyc+YZzEL9VkRyvxtVbXLb7ESwCiHjP2uSk=;\n\th=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:\n\tFrom;\n\tb=uQ8P30OCJqqxquQW3T2fl0360roJVaoVGcqfsf5ntsvmUiH1TiJ8hOCP/kcbhE+RF\n\tb5QL7JA3FXArckYX6j1l5LnSCPm0drl8/ZFtOAuDH2v0ntU2JTvo0V/RLtvkHK5Q+4\n\t0qCcOVV1PGKJegMNJ0UKhxpnuzMoi5KNyPmK8eoaJ6VXUIAlFUCZhRGbd+XCP/u4Q5\n\t3JgX3deq8QbFiF/7zb+vLurNA7JfsWEIflfqJ+p3o0isszqG3SoZHgZd60n3QS5dki\n\tWgvQ5jD9dDPr2zkF7pzGAMSJGd/2Yh7CI7MOaNYunqfbDsI+j3NoX/M3QKl61Dl7Qq\n\tg016pDOuQqIgg==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1648416526;\n\tbh=XE0DymOSOyc+YZzEL9VkRyvxtVbXLb7ESwCiHjP2uSk=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=LFsx08Lvu9NfVinb/f2m81+p0r5B2cIcw5gflTvWsbUii73OB37tll/TLfm86jOSW\n\tPhUFFMY5xq7pYtgOrjOQ4FrpNmq27pi/1PJCyDUqMCps/F/eSTQ3b8fqb4Yskt+4JN\n\ts1hm0x+DB/ik0o5aNMwEuyDxCbRbiVH8wXvIJ52c="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"LFsx08Lv\"; dkim-atps=neutral","Date":"Mon, 28 Mar 2022 00:28:44 +0300","To":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Message-ID":"<YkDXDC238H/dPdPl@pendragon.ideasonboard.com>","References":"<20220325103410.38580-1-umang.jain@ideasonboard.com>\n\t<20220325103410.38580-4-umang.jain@ideasonboard.com>\n\t<164820893730.1341993.2360852856251400278@Monstersaurus>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<164820893730.1341993.2360852856251400278@Monstersaurus>","Subject":"Re: [libcamera-devel] [PATCH v4 3/3] ipa: ipu3: Ensure controls\n\texists in before they are queried","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>","From":"Laurent Pinchart via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>","Reply-To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]