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

Message ID 20190426141332.2782-1-niklas.soderlund@ragnatech.se
State Accepted
Commit ff24be7022b39533cce219468b6fa3ce84460f94
Headers show
Series
  • [libcamera-devel,v2] libcamera: camera: Check requests before queueing them
Related show

Commit Message

Niklas Söderlund April 26, 2019, 2:13 p.m. UTC
Make sure all requests queued to a camera only contain streams which
have been configured and belong 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 27, 2019, 9:19 a.m. UTC | #1
Hi Niklas,

Thank you for the patch.

On Fri, Apr 26, 2019 at 04:13:32PM +0200, Niklas Söderlund wrote:
> Make sure all requests queued to a camera only contain streams which
> have been configured and belong to the camera.
> 
> Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

> ---
>  src/libcamera/camera.cpp | 9 +++++++++
>  1 file changed, 9 insertions(+)
> 
> diff --git a/src/libcamera/camera.cpp b/src/libcamera/camera.cpp
> index 655996f26224ef49..9cea3fd06238c1cb 100644
> --- a/src/libcamera/camera.cpp
> +++ b/src/libcamera/camera.cpp
> @@ -732,6 +732,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 invalid
>   */
>  int Camera::queueRequest(Request *request)
>  {
> @@ -741,6 +742,14 @@ int Camera::queueRequest(Request *request)
>  	if (!stateIs(CameraRunning))
>  		return -EACCES;
>  
> +	for (auto const &it : request->buffers()) {
> +		Stream *stream = it.first;
> +		if (activeStreams_.find(stream) == activeStreams_.end()) {
> +			LOG(Camera, Error) << "Invalid request";
> +			return -EINVAL;
> +		}
> +	}
> +
>  	int ret = request->prepare();
>  	if (ret) {
>  		LOG(Camera, Error) << "Failed to prepare request";
Niklas Söderlund April 28, 2019, 9:36 a.m. UTC | #2
Hi,

On 2019-04-27 12:19:51 +0300, Laurent Pinchart wrote:
> Hi Niklas,
> 
> Thank you for the patch.
> 
> On Fri, Apr 26, 2019 at 04:13:32PM +0200, Niklas Söderlund wrote:
> > Make sure all requests queued to a camera only contain streams which
> > have been configured and belong to the camera.
> > 
> > Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
> 
> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

Thanks, pushed to master.

> 
> > ---
> >  src/libcamera/camera.cpp | 9 +++++++++
> >  1 file changed, 9 insertions(+)
> > 
> > diff --git a/src/libcamera/camera.cpp b/src/libcamera/camera.cpp
> > index 655996f26224ef49..9cea3fd06238c1cb 100644
> > --- a/src/libcamera/camera.cpp
> > +++ b/src/libcamera/camera.cpp
> > @@ -732,6 +732,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 invalid
> >   */
> >  int Camera::queueRequest(Request *request)
> >  {
> > @@ -741,6 +742,14 @@ int Camera::queueRequest(Request *request)
> >  	if (!stateIs(CameraRunning))
> >  		return -EACCES;
> >  
> > +	for (auto const &it : request->buffers()) {
> > +		Stream *stream = it.first;
> > +		if (activeStreams_.find(stream) == activeStreams_.end()) {
> > +			LOG(Camera, Error) << "Invalid request";
> > +			return -EINVAL;
> > +		}
> > +	}
> > +
> >  	int ret = request->prepare();
> >  	if (ret) {
> >  		LOG(Camera, Error) << "Failed to prepare request";
> 
> -- 
> Regards,
> 
> Laurent Pinchart

Patch

diff --git a/src/libcamera/camera.cpp b/src/libcamera/camera.cpp
index 655996f26224ef49..9cea3fd06238c1cb 100644
--- a/src/libcamera/camera.cpp
+++ b/src/libcamera/camera.cpp
@@ -732,6 +732,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 invalid
  */
 int Camera::queueRequest(Request *request)
 {
@@ -741,6 +742,14 @@  int Camera::queueRequest(Request *request)
 	if (!stateIs(CameraRunning))
 		return -EACCES;
 
+	for (auto const &it : request->buffers()) {
+		Stream *stream = it.first;
+		if (activeStreams_.find(stream) == activeStreams_.end()) {
+			LOG(Camera, Error) << "Invalid request";
+			return -EINVAL;
+		}
+	}
+
 	int ret = request->prepare();
 	if (ret) {
 		LOG(Camera, Error) << "Failed to prepare request";