From patchwork Tue Apr 16 13:42:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 1006 Return-Path: Received: from relay9-d.mail.gandi.net (relay9-d.mail.gandi.net [217.70.183.199]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id A8F2B60DC8 for ; Tue, 16 Apr 2019 15:41:28 +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 relay9-d.mail.gandi.net (Postfix) with ESMTPSA id 3F950FF808; Tue, 16 Apr 2019 13:41:28 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Tue, 16 Apr 2019 15:42:08 +0200 Message-Id: <20190416134210.21097-6-jacopo@jmondi.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190416134210.21097-1-jacopo@jmondi.org> References: <20190416134210.21097-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v6 5/7] libcamera: camera: Validate Request befor 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: Tue, 16 Apr 2019 13:41:29 -0000 Validate the Request before proceeding to prepare it at Camera::queueRequest() time. For now limit the validation to making sure the Request contains at least one Stream to capture from. Signed-off-by: Jacopo Mondi Reviewed-by: Laurent Pinchart --- src/libcamera/camera.cpp | 10 ++++++++-- src/libcamera/request.cpp | 15 ++++++++++++++- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/libcamera/camera.cpp b/src/libcamera/camera.cpp index 2d0a80664214..0709047341d7 100644 --- a/src/libcamera/camera.cpp +++ b/src/libcamera/camera.cpp @@ -714,8 +714,14 @@ Request *Camera::createRequest() * \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. + * 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 5e86c8e10128..12a3c5204f24 100644 --- a/src/libcamera/request.cpp +++ b/src/libcamera/request.cpp @@ -115,10 +115,23 @@ Buffer *Request::findBuffer(Stream *stream) const */ /** - * \brief Prepare the resources for the completion handler + * \brief Prepare and validate the request for the completion handler + * + * This method prepares resources and validates the request to prepare it for + * capture operations. + * + * Requests that contain no buffers are invalid and are rejected by this method. + * + * \return 0 on success a negative error code otherwise + * \retval -EVINAL The request is invalid */ int Request::prepare() { + if (!hasPendingBuffers()) { + LOG(Request, Error) << "Invalid request due to missing buffers"; + return -EINVAL; + } + for (auto const &pair : bufferMap_) { Buffer *buffer = pair.second; pending_.insert(buffer);