From patchwork Thu Apr 18 10:47:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 1038 Return-Path: Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 6C01A60DC6 for ; Thu, 18 Apr 2019 12:46:34 +0200 (CEST) X-Originating-IP: 2.224.242.101 Received: from uno.lan (2-224-242-101.ip172.fastwebnet.it [2.224.242.101]) (Authenticated sender: jacopo@jmondi.org) by relay5-d.mail.gandi.net (Postfix) with ESMTPSA id F3E4A1C0007; Thu, 18 Apr 2019 10:46:33 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Thu, 18 Apr 2019 12:47:07 +0200 Message-Id: <20190418104715.22622-7-jacopo@jmondi.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190418104715.22622-1-jacopo@jmondi.org> References: <20190418104715.22622-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v5 06/14] libcamera: camera: Validate Request before queueing it X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 18 Apr 2019 10:46:34 -0000 Extend the Request::prepare() operation to validate the request before preparing it. Return an error if the request is invalid, which for now is limited to ensuring that the request contains at least one buffer. Signed-off-by: Jacopo Mondi --- src/libcamera/camera.cpp | 11 ++++++++--- src/libcamera/request.cpp | 12 +++++++++++- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/libcamera/camera.cpp b/src/libcamera/camera.cpp index 2d0a80664214..75a21008070b 100644 --- a/src/libcamera/camera.cpp +++ b/src/libcamera/camera.cpp @@ -713,9 +713,14 @@ Request *Camera::createRequest() * \brief Queue a request to the camera * \param[in] request The request to queue to the camera * - * This method queues a \a request allocated with createRequest() to the camera - * for capture. Once the request has been queued, the camera will notify its - * completion through the \ref requestCompleted signal. + * This method queues a \a request to the camera for capture. + * + * After allocating the request with createRequest(), the application shall + * fill it with at least one capture buffer before queuing it. Requests that + * contain no buffers are invalid and are rejected without being queued. + * + * Once the request has been queued, the camera will notify its completion + * through the \ref requestCompleted signal. * * Ownership of the request is transferred to the camera. It will be deleted * automatically after it completes. diff --git a/src/libcamera/request.cpp b/src/libcamera/request.cpp index e5c25d2c6988..502048683245 100644 --- a/src/libcamera/request.cpp +++ b/src/libcamera/request.cpp @@ -115,7 +115,12 @@ Buffer *Request::findBuffer(Stream *stream) const */ /** - * \brief Prepare the resources for the completion handler + * \brief Validate the request and prepare it for the completion handler + * + * Requests that contain no buffers are invalid and are rejected. + * + * \return 0 on success or a negative error code otherwise + * \retval -EINVAL The request is invalid */ int Request::prepare() { @@ -124,6 +129,11 @@ int Request::prepare() pending_.insert(buffer); } + if (!hasPendingBuffers()) { + LOG(Request, Error) << "Invalid request due to missing buffers"; + return -EINVAL; + } + return 0; }