[libcamera-devel,v1,1/2] libcamera: v4l2_videodevice: Guard against releasing unallocated buffers
diff mbox series

Message ID 20221028115200.8138-2-naush@raspberrypi.com
State Superseded
Headers show
Series
  • Buffer cleanup fixes
Related show

Commit Message

Naushir Patuck Oct. 28, 2022, 11:51 a.m. UTC
releaseBuffers() unconditionally calls ioctl(REQBUFS, 0) to release device
buffer allocations through the close() and class destructor functions. If
another libcamera process is running concurrently with a different sensor, it
would cause the ioctl to fail in the kernel because the buffer queue is owned
owned by the other process. This in turn would cause libcamera to generate an
error log message.

Fix this by ensuring the releaseBuffers() only calls ioctl(REQBUFS, 0) if there
have been buffers previously allocated by the device. This is done by testing
the presense of the V4L2BufferCache in the object.

Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
---
 src/libcamera/v4l2_videodevice.cpp | 3 +++
 1 file changed, 3 insertions(+)

Comments

Naushir Patuck Oct. 28, 2022, 1:37 p.m. UTC | #1
Apologies!  This was not meant to be the patch I wanted to push.  My brain
has shut down for the weekend.
I'll push an update for the correct patch in reply to this one.

Naush



On Fri, 28 Oct 2022 at 12:52, Naushir Patuck <naush@raspberrypi.com> wrote:

> releaseBuffers() unconditionally calls ioctl(REQBUFS, 0) to release device
> buffer allocations through the close() and class destructor functions. If
> another libcamera process is running concurrently with a different sensor,
> it
> would cause the ioctl to fail in the kernel because the buffer queue is
> owned
> owned by the other process. This in turn would cause libcamera to generate
> an
> error log message.
>
> Fix this by ensuring the releaseBuffers() only calls ioctl(REQBUFS, 0) if
> there
> have been buffers previously allocated by the device. This is done by
> testing
> the presense of the V4L2BufferCache in the object.
>
> Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
> ---
>  src/libcamera/v4l2_videodevice.cpp | 3 +++
>  1 file changed, 3 insertions(+)
>
> diff --git a/src/libcamera/v4l2_videodevice.cpp
> b/src/libcamera/v4l2_videodevice.cpp
> index e30858c9fa02..ed446c25e45f 100644
> --- a/src/libcamera/v4l2_videodevice.cpp
> +++ b/src/libcamera/v4l2_videodevice.cpp
> @@ -1533,6 +1533,9 @@ int V4L2VideoDevice::importBuffers(unsigned int
> count)
>   */
>  int V4L2VideoDevice::releaseBuffers()
>  {
> +       if (!cache_)
> +               return;
> +
>         LOG(V4L2, Debug) << "Releasing buffers";
>
>         delete cache_;
> --
> 2.25.1
>
>

Patch
diff mbox series

diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp
index e30858c9fa02..ed446c25e45f 100644
--- a/src/libcamera/v4l2_videodevice.cpp
+++ b/src/libcamera/v4l2_videodevice.cpp
@@ -1533,6 +1533,9 @@  int V4L2VideoDevice::importBuffers(unsigned int count)
  */
 int V4L2VideoDevice::releaseBuffers()
 {
+	if (!cache_)
+		return;
+
 	LOG(V4L2, Debug) << "Releasing buffers";
 
 	delete cache_;