[{"id":1441,"web_url":"https://patchwork.libcamera.org/comment/1441/","msgid":"<20190417161322.drkcrcxn7vvd4oly@uno.localdomain>","date":"2019-04-17T16:13:22","subject":"Re: [libcamera-devel] [PATCH v7 6/8] libcamera: camera: Validate\n\tRequest before queueing it","submitter":{"id":3,"url":"https://patchwork.libcamera.org/api/people/3/","name":"Jacopo Mondi","email":"jacopo@jmondi.org"},"content":"On Wed, Apr 17, 2019 at 03:58:56PM +0200, Jacopo Mondi wrote:\n> Extend the Request::prepare() operation to validate the request before\n> preparing it. Return an error if the request is invalid, which for now\n> is limited to ensuring that the request contains at least one buffer.\n>\n> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>\n> ---\n>  src/libcamera/camera.cpp  | 11 ++++++++---\n>  src/libcamera/request.cpp | 12 +++++++++++-\n>  2 files changed, 19 insertions(+), 4 deletions(-)\n>\n> diff --git a/src/libcamera/camera.cpp b/src/libcamera/camera.cpp\n> index 2d0a80664214..75a21008070b 100644\n> --- a/src/libcamera/camera.cpp\n> +++ b/src/libcamera/camera.cpp\n> @@ -713,9 +713,14 @@ Request *Camera::createRequest()\n>   * \\brief Queue a request to the camera\n>   * \\param[in] request The request to queue to the camera\n>   *\n> - * This method queues a \\a request allocated with createRequest() to the camera\n> - * for capture. Once the request has been queued, the camera will notify its\n> - * completion through the \\ref requestCompleted signal.\n> + * This method queues a \\a request to the camera for capture.\n> + *\n> + * After allocating the request with createRequest(), the application shall\n> + * fill it with at least one capture buffer before queuing it. Requests that\n> + * contain no buffers are invalid and are rejected without being queued.\n> + *\n> + * Once the request has been queued, the camera will notify its completion\n> + * through the \\ref requestCompleted signal.\n>   *\n>   * Ownership of the request is transferred to the camera. It will be deleted\n>   * automatically after it completes.\n> diff --git a/src/libcamera/request.cpp b/src/libcamera/request.cpp\n> index e5c25d2c6988..9fc8c6845578 100644\n> --- a/src/libcamera/request.cpp\n> +++ b/src/libcamera/request.cpp\n> @@ -115,10 +115,20 @@ Buffer *Request::findBuffer(Stream *stream) const\n>   */\n>\n>  /**\n> - * \\brief Prepare the resources for the completion handler\n> + * \\brief Validate the request and prepare it for the completion handler\n> + *\n> + * Requests that contain no buffers are invalid and are rejected.\n> + *\n> + * \\return 0 on success or a negative error code otherwise\n> + * \\retval -EINVAL The request is invalid\n>   */\n>  int Request::prepare()\n>  {\n> +\tif (!hasPendingBuffers()) {\n> +\t\tLOG(Request, Error) << \"Invalid request due to missing buffers\";\n> +\t\treturn -EINVAL;\n> +\t}\n> +\n\nOh, this is so stupid!\nhasPendingBuffers() checks for pending_ to be empty, and pending_ is\nhere below populated :(\n\nSorry about this, I moved it up to skip the below loop if no buffers\nwere available, not a great idea it seems!\n\n>  \tfor (auto const &pair : bufferMap_) {\n>  \t\tBuffer *buffer = pair.second;\n>  \t\tpending_.insert(buffer);\n> --\n> 2.21.0\n>","headers":{"Return-Path":"<jacopo@jmondi.org>","Received":["from relay1-d.mail.gandi.net (relay1-d.mail.gandi.net\n\t[217.70.183.193])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 4D00A60DBF\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 17 Apr 2019 18:12:31 +0200 (CEST)","from uno.localdomain (2-224-242-101.ip172.fastwebnet.it\n\t[2.224.242.101]) (Authenticated sender: jacopo@jmondi.org)\n\tby relay1-d.mail.gandi.net (Postfix) with ESMTPSA id E732E240012\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 17 Apr 2019 16:12:30 +0000 (UTC)"],"X-Originating-IP":"2.224.242.101","Date":"Wed, 17 Apr 2019 18:13:22 +0200","From":"Jacopo Mondi <jacopo@jmondi.org>","To":"libcamera-devel@lists.libcamera.org","Message-ID":"<20190417161322.drkcrcxn7vvd4oly@uno.localdomain>","References":"<20190417135858.23914-1-jacopo@jmondi.org>\n\t<20190417135858.23914-7-jacopo@jmondi.org>","MIME-Version":"1.0","Content-Type":"multipart/signed; micalg=pgp-sha256;\n\tprotocol=\"application/pgp-signature\"; boundary=\"hgjdtubydwxffrvz\"","Content-Disposition":"inline","In-Reply-To":"<20190417135858.23914-7-jacopo@jmondi.org>","User-Agent":"NeoMutt/20180716","Subject":"Re: [libcamera-devel] [PATCH v7 6/8] libcamera: camera: Validate\n\tRequest before queueing it","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.23","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":"Wed, 17 Apr 2019 16:12:31 -0000"}},{"id":1448,"web_url":"https://patchwork.libcamera.org/comment/1448/","msgid":"<20190418125207.GO4806@pendragon.ideasonboard.com>","date":"2019-04-18T12:52:07","subject":"Re: [libcamera-devel] [PATCH v7 6/8] libcamera: camera: Validate\n\tRequest before queueing it","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Jacopo,\n\nThank you for the patch.\n\nOn Wed, Apr 17, 2019 at 06:13:22PM +0200, Jacopo Mondi wrote:\n> On Wed, Apr 17, 2019 at 03:58:56PM +0200, Jacopo Mondi wrote:\n> > Extend the Request::prepare() operation to validate the request before\n> > preparing it. Return an error if the request is invalid, which for now\n> > is limited to ensuring that the request contains at least one buffer.\n> >\n> > Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>\n> > ---\n> >  src/libcamera/camera.cpp  | 11 ++++++++---\n> >  src/libcamera/request.cpp | 12 +++++++++++-\n> >  2 files changed, 19 insertions(+), 4 deletions(-)\n> >\n> > diff --git a/src/libcamera/camera.cpp b/src/libcamera/camera.cpp\n> > index 2d0a80664214..75a21008070b 100644\n> > --- a/src/libcamera/camera.cpp\n> > +++ b/src/libcamera/camera.cpp\n> > @@ -713,9 +713,14 @@ Request *Camera::createRequest()\n> >   * \\brief Queue a request to the camera\n> >   * \\param[in] request The request to queue to the camera\n> >   *\n> > - * This method queues a \\a request allocated with createRequest() to the camera\n> > - * for capture. Once the request has been queued, the camera will notify its\n> > - * completion through the \\ref requestCompleted signal.\n> > + * This method queues a \\a request to the camera for capture.\n> > + *\n> > + * After allocating the request with createRequest(), the application shall\n> > + * fill it with at least one capture buffer before queuing it. Requests that\n> > + * contain no buffers are invalid and are rejected without being queued.\n> > + *\n> > + * Once the request has been queued, the camera will notify its completion\n> > + * through the \\ref requestCompleted signal.\n> >   *\n> >   * Ownership of the request is transferred to the camera. It will be deleted\n> >   * automatically after it completes.\n> > diff --git a/src/libcamera/request.cpp b/src/libcamera/request.cpp\n> > index e5c25d2c6988..9fc8c6845578 100644\n> > --- a/src/libcamera/request.cpp\n> > +++ b/src/libcamera/request.cpp\n> > @@ -115,10 +115,20 @@ Buffer *Request::findBuffer(Stream *stream) const\n> >   */\n> >\n> >  /**\n> > - * \\brief Prepare the resources for the completion handler\n> > + * \\brief Validate the request and prepare it for the completion handler\n> > + *\n> > + * Requests that contain no buffers are invalid and are rejected.\n> > + *\n> > + * \\return 0 on success or a negative error code otherwise\n> > + * \\retval -EINVAL The request is invalid\n> >   */\n> >  int Request::prepare()\n> >  {\n> > +\tif (!hasPendingBuffers()) {\n> > +\t\tLOG(Request, Error) << \"Invalid request due to missing buffers\";\n> > +\t\treturn -EINVAL;\n> > +\t}\n> > +\n> \n> Oh, this is so stupid!\n> hasPendingBuffers() checks for pending_ to be empty, and pending_ is\n> here below populated :(\n> \n> Sorry about this, I moved it up to skip the below loop if no buffers\n> were available, not a great idea it seems!\n\nLet's keep it below (or check bufferMap_.empty() instead, that may be\neven better), and you'll have my\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n:-)\n\n> >  \tfor (auto const &pair : bufferMap_) {\n> >  \t\tBuffer *buffer = pair.second;\n> >  \t\tpending_.insert(buffer);","headers":{"Return-Path":"<laurent.pinchart@ideasonboard.com>","Received":["from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id CBB0A60DC0\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 18 Apr 2019 14:52:16 +0200 (CEST)","from pendragon.ideasonboard.com\n\t(dfj612yhrgyx302h3jwwy-3.rev.dnainternet.fi\n\t[IPv6:2001:14ba:21f5:5b00:ce28:277f:58d7:3ca4])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 2A26D333;\n\tThu, 18 Apr 2019 14:52:16 +0200 (CEST)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1555591936;\n\tbh=v3tPT6kRzRlLVo81JpwsisYZDNYlNig+YubxMuBfeeA=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=OagcXbhas8GQ20l8AC26lkTDE2MkWKFivpjYwwf3Li9UfWNP8ZbuElIcQwE0LbHi8\n\tYoOd5Lk8IR1ma8mSGFz9by7S6Fgshmfkv68egJgSPCd3JE2N06ZS/7YLuXAp7ZhG1Z\n\tnJCHCk7dEGn8JCa8RC6iOYpzrzWotLbRpnxUiBVo=","Date":"Thu, 18 Apr 2019 15:52:07 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Jacopo Mondi <jacopo@jmondi.org>","Cc":"libcamera-devel@lists.libcamera.org","Message-ID":"<20190418125207.GO4806@pendragon.ideasonboard.com>","References":"<20190417135858.23914-1-jacopo@jmondi.org>\n\t<20190417135858.23914-7-jacopo@jmondi.org>\n\t<20190417161322.drkcrcxn7vvd4oly@uno.localdomain>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20190417161322.drkcrcxn7vvd4oly@uno.localdomain>","User-Agent":"Mutt/1.10.1 (2018-07-13)","Subject":"Re: [libcamera-devel] [PATCH v7 6/8] libcamera: camera: Validate\n\tRequest before queueing it","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.23","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":"Thu, 18 Apr 2019 12:52:17 -0000"}}]