[v2,1/4] libcamera: v4l2_videodevice: streamOff(): Handle device disconnection
diff mbox series

Message ID 20261202141623.1375959-2-barnabas.pocze@ideasonboard.com
State New
Headers show
Series
  • libcamera: atomic-disconnects
Related show

Commit Message

Barnabás Pőcze Dec. 2, 2026, 2:16 p.m. UTC
If the `VIDIOC_STREAMOFF` reports `ENODEV`, meaning that the device is
no longer available/connected, then proceed normally and cancel all
pending buffers, and do not report an error.

For example, this relevant for UVC, as `VIDIOC_STREAMOFF` will report
`ENODEV` after disconnection, and returning buffers is crucial as
the "uvcvideo" depends on `streamOff()` returning all pending buffers.
Otherwise some requests will not be completed, leading to an assertion
failure in `PipelineHandler::stop()`.

Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>
---
 src/libcamera/v4l2_videodevice.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Kieran Bingham Dec. 2, 2026, 3:01 p.m. UTC | #1
Quoting Barnabás Pőcze (2026-12-02 14:16:20)
> If the `VIDIOC_STREAMOFF` reports `ENODEV`, meaning that the device is
> no longer available/connected, then proceed normally and cancel all
> pending buffers, and do not report an error.
> 
> For example, this relevant for UVC, as `VIDIOC_STREAMOFF` will report
> `ENODEV` after disconnection, and returning buffers is crucial as
> the "uvcvideo" depends on `streamOff()` returning all pending buffers.
> Otherwise some requests will not be completed, leading to an assertion
> failure in `PipelineHandler::stop()`.
> 
> Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>

Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>

> ---
>  src/libcamera/v4l2_videodevice.cpp | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp
> index 41dc5d0f65..35408fa13d 100644
> --- a/src/libcamera/v4l2_videodevice.cpp
> +++ b/src/libcamera/v4l2_videodevice.cpp
> @@ -2031,7 +2031,7 @@ int V4L2VideoDevice::streamOff()
>                 watchdog_.stop();
>  
>         ret = ioctl(VIDIOC_STREAMOFF, &bufferType_);
> -       if (ret < 0) {
> +       if (ret < 0 && ret != -ENODEV) {
>                 LOG(V4L2, Error)
>                         << "Failed to stop streaming: " << strerror(-ret);
>                 return ret;
> -- 
> 2.56.1
>

Patch
diff mbox series

diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp
index 41dc5d0f65..35408fa13d 100644
--- a/src/libcamera/v4l2_videodevice.cpp
+++ b/src/libcamera/v4l2_videodevice.cpp
@@ -2031,7 +2031,7 @@  int V4L2VideoDevice::streamOff()
 		watchdog_.stop();
 
 	ret = ioctl(VIDIOC_STREAMOFF, &bufferType_);
-	if (ret < 0) {
+	if (ret < 0 && ret != -ENODEV) {
 		LOG(V4L2, Error)
 			<< "Failed to stop streaming: " << strerror(-ret);
 		return ret;