[libcamera-devel,v3,20/22] v4l2: v4l2_camera_proxy: Don't allow buffers to be freed if still mmaped

Message ID 20200623190836.53446-21-paul.elder@ideasonboard.com
State Superseded
Headers show
Series
  • Support v4l2-compliance
Related show

Commit Message

Paul Elder June 23, 2020, 7:08 p.m. UTC
In VIDIOC_REQBUFS with count = 0, if the buffers are still mmaped, they
should not be allowed to be freed. Add a check for this.

Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>

---
No change in v3

New in v2
- split from "Fix v4l2-compliance streaming tests"
---
 src/v4l2/v4l2_camera_proxy.cpp | 3 +++
 1 file changed, 3 insertions(+)

Comments

Laurent Pinchart June 23, 2020, 11:10 p.m. UTC | #1
Hi Paul,

Thank you for the patch.

On Wed, Jun 24, 2020 at 04:08:34AM +0900, Paul Elder wrote:
> In VIDIOC_REQBUFS with count = 0, if the buffers are still mmaped, they
> should not be allowed to be freed. Add a check for this.
> 
> Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>
> 
> ---
> No change in v3
> 
> New in v2
> - split from "Fix v4l2-compliance streaming tests"
> ---
>  src/v4l2/v4l2_camera_proxy.cpp | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/src/v4l2/v4l2_camera_proxy.cpp b/src/v4l2/v4l2_camera_proxy.cpp
> index dd09951..ce0d755 100644
> --- a/src/v4l2/v4l2_camera_proxy.cpp
> +++ b/src/v4l2/v4l2_camera_proxy.cpp
> @@ -471,6 +471,9 @@ int V4L2CameraProxy::vidioc_reqbufs(V4L2CameraFile *file, struct v4l2_requestbuf
>  	memset(arg->reserved, 0, sizeof(arg->reserved));
>  
>  	if (arg->count == 0) {

If we decide not to support buffer orphaning, despite reporting a v5.2.0
version, we should at least have

		/** \todo Add buffer orphaning support */

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

> +		if (!mmaps_.empty())
> +			return -EBUSY;
> +
>  		if (vcam_->isRunning())
>  			return -EBUSY;
>

Patch

diff --git a/src/v4l2/v4l2_camera_proxy.cpp b/src/v4l2/v4l2_camera_proxy.cpp
index dd09951..ce0d755 100644
--- a/src/v4l2/v4l2_camera_proxy.cpp
+++ b/src/v4l2/v4l2_camera_proxy.cpp
@@ -471,6 +471,9 @@  int V4L2CameraProxy::vidioc_reqbufs(V4L2CameraFile *file, struct v4l2_requestbuf
 	memset(arg->reserved, 0, sizeof(arg->reserved));
 
 	if (arg->count == 0) {
+		if (!mmaps_.empty())
+			return -EBUSY;
+
 		if (vcam_->isRunning())
 			return -EBUSY;