summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRicardo Ribalda <ribalda@chromium.org>2025-03-27 21:05:27 +0000
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2025-07-06 11:04:10 +0200
commitc3f5d2bad0caedcad0e3d3063f1d67afc77c3847 (patch)
treebaa8793d40bb309cbd3337dbf5588161cf589f6e
parent44f86733b175f3b7c7f2fa47635e83e657c59046 (diff)
media: uvcvideo: Keep streaming state in the file handle
[ Upstream commit 14f6e205e5599c2217b68c05b903ce162e7c1e27 ] Add a variable in the file handle state to figure out if a camera is in the streaming state or not. This variable will be used in the future for power management policies. Now that we are at it, make use of guards to simplify the code. Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Hans de Goede <hdegoede@redhat.com> Signed-off-by: Ricardo Ribalda <ribalda@chromium.org> Message-ID: <20250327-uvc-granpower-ng-v6-1-35a2357ff348@chromium.org> Signed-off-by: Hans de Goede <hdegoede@redhat.com> Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl> Stable-dep-of: a70705d3c020 ("media: uvcvideo: Rollback non processed entities on error") Signed-off-by: Sasha Levin <sashal@kernel.org>
-rw-r--r--drivers/media/usb/uvc/uvc_v4l2.c18
-rw-r--r--drivers/media/usb/uvc/uvcvideo.h1
2 files changed, 14 insertions, 5 deletions
diff --git a/drivers/media/usb/uvc/uvc_v4l2.c b/drivers/media/usb/uvc/uvc_v4l2.c
index 39065db44e86..22886b47d81c 100644
--- a/drivers/media/usb/uvc/uvc_v4l2.c
+++ b/drivers/media/usb/uvc/uvc_v4l2.c
@@ -841,11 +841,18 @@ static int uvc_ioctl_streamon(struct file *file, void *fh,
if (!uvc_has_privileges(handle))
return -EBUSY;
- mutex_lock(&stream->mutex);
+ guard(mutex)(&stream->mutex);
+
+ if (handle->is_streaming)
+ return 0;
+
ret = uvc_queue_streamon(&stream->queue, type);
- mutex_unlock(&stream->mutex);
+ if (ret)
+ return ret;
- return ret;
+ handle->is_streaming = true;
+
+ return 0;
}
static int uvc_ioctl_streamoff(struct file *file, void *fh,
@@ -857,9 +864,10 @@ static int uvc_ioctl_streamoff(struct file *file, void *fh,
if (!uvc_has_privileges(handle))
return -EBUSY;
- mutex_lock(&stream->mutex);
+ guard(mutex)(&stream->mutex);
+
uvc_queue_streamoff(&stream->queue, type);
- mutex_unlock(&stream->mutex);
+ handle->is_streaming = false;
return 0;
}
diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvideo.h
index b4ee701835fc..5ceb01e7831a 100644
--- a/drivers/media/usb/uvc/uvcvideo.h
+++ b/drivers/media/usb/uvc/uvcvideo.h
@@ -630,6 +630,7 @@ struct uvc_fh {
struct uvc_streaming *stream;
enum uvc_handle_state state;
unsigned int pending_async_ctrls;
+ bool is_streaming;
};
/* ------------------------------------------------------------------------