From patchwork Mon Apr 15 23:18:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 998 Return-Path: Received: from relay8-d.mail.gandi.net (relay8-d.mail.gandi.net [217.70.183.201]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 039DC60DC8 for ; Tue, 16 Apr 2019 01:18:22 +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 relay8-d.mail.gandi.net (Postfix) with ESMTPSA id 8A9161BF203; Mon, 15 Apr 2019 23:18:21 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Tue, 16 Apr 2019 01:18:57 +0200 Message-Id: <20190415231859.9747-6-jacopo@jmondi.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190415231859.9747-1-jacopo@jmondi.org> References: <20190415231859.9747-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v5 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: Mon, 15 Apr 2019 23:18:22 -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 --- src/libcamera/camera.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/libcamera/camera.cpp b/src/libcamera/camera.cpp index 21caa24b90b5..e93e7b3b8477 100644 --- a/src/libcamera/camera.cpp +++ b/src/libcamera/camera.cpp @@ -715,8 +715,9 @@ 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 and validates it by making sure it contains at least one stream + * where to capture from. 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. @@ -724,6 +725,7 @@ Request *Camera::createRequest() * \return 0 on success or a negative error code otherwise * \retval -ENODEV The camera has been disconnected from the system * \retval -EACCES The camera is not running so requests can't be queued + * \retval -EINVAL The request is not valid */ int Camera::queueRequest(Request *request) { @@ -733,6 +735,15 @@ int Camera::queueRequest(Request *request) if (!stateIs(CameraRunning)) return -EACCES; + /* + * \todo: Centralize validation if it gets more complex and update + * the documentation. + */ + if (request->empty()) { + LOG(Camera, Error) << "Invalid request"; + return -EINVAL; + } + int ret = request->prepare(); if (ret) { LOG(Camera, Error) << "Failed to prepare request";