[libcamera-devel] libcamera: camera: Check requests before queueing them

Message ID 20190422180740.21878-1-niklas.soderlund@ragnatech.se
State Superseded
Headers show
Series
  • [libcamera-devel] libcamera: camera: Check requests before queueing them
Related show

Commit Message

Niklas Söderlund April 22, 2019, 6:07 p.m. UTC
Make sure all requests queued to a camera only contains streams which
have been configured and belongs to the camera.

Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
---
 src/libcamera/camera.cpp | 9 +++++++++
 1 file changed, 9 insertions(+)

Comments

Laurent Pinchart April 22, 2019, 9:15 p.m. UTC | #1
Hi Niklas,

Thank you for the patch.

On Mon, Apr 22, 2019 at 08:07:40PM +0200, Niklas Söderlund wrote:
> Make sure all requests queued to a camera only contains streams which

s/contains/contain/

> have been configured and belongs to the camera.

s/belongs/belong/

> 
> Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
> ---
>  src/libcamera/camera.cpp | 9 +++++++++
>  1 file changed, 9 insertions(+)
> 
> diff --git a/src/libcamera/camera.cpp b/src/libcamera/camera.cpp
> index 655996f26224ef49..36c7584e823eb580 100644
> --- a/src/libcamera/camera.cpp
> +++ b/src/libcamera/camera.cpp
> @@ -747,6 +747,15 @@ int Camera::queueRequest(Request *request)
>  		return ret;
>  	}
>  
> +	for (auto const &it : request->buffers()) {
> +		Stream *stream = it.first;
> +		if (activeStreams_.find(stream) == activeStreams_.end()) {
> +			LOG(Camera, Error)
> +				<< "Attempt to queue request with invalid stream";
> +			return -EINVAL;

You should document the -EINVAL error code in the return values of
Camera::queueRequest().

> +		}
> +	}
> +

Should this be done before calling Request::prepare() ? There's no point
in preparing the request if the streams are not valid.

>  	return pipe_->queueRequest(this, request);
>  }
>

Patch

diff --git a/src/libcamera/camera.cpp b/src/libcamera/camera.cpp
index 655996f26224ef49..36c7584e823eb580 100644
--- a/src/libcamera/camera.cpp
+++ b/src/libcamera/camera.cpp
@@ -747,6 +747,15 @@  int Camera::queueRequest(Request *request)
 		return ret;
 	}
 
+	for (auto const &it : request->buffers()) {
+		Stream *stream = it.first;
+		if (activeStreams_.find(stream) == activeStreams_.end()) {
+			LOG(Camera, Error)
+				<< "Attempt to queue request with invalid stream";
+			return -EINVAL;
+		}
+	}
+
 	return pipe_->queueRequest(this, request);
 }