aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorRicardo Ribalda <ribalda@chromium.org>2025-03-27 21:05:28 +0000
committerHans Verkuil <hverkuil@xs4all.nl>2025-05-09 15:29:12 +0200
commit2f101572c0a3ae4630f2a57c8033b78ee84ac5a6 (patch)
tree5373baf5fb9ebaa150774d1699d5d51654bd184c
parentmedia: uvcvideo: Keep streaming state in the file handle (diff)
downloadwireguard-linux-2f101572c0a3ae4630f2a57c8033b78ee84ac5a6.tar.xz
wireguard-linux-2f101572c0a3ae4630f2a57c8033b78ee84ac5a6.zip
media: uvcvideo: Create uvc_pm_(get|put) functions
Most of the times that we have to call uvc_status_(get|put) we need to call the usb_autopm_ functions. Create a new pair of functions that automate this for us. This simplifies the current code and future PM changes in the driver. Reviewed-by: Hans de Goede <hdegoede@redhat.com> Signed-off-by: Ricardo Ribalda <ribalda@chromium.org> Message-ID: <20250327-uvc-granpower-ng-v6-2-35a2357ff348@chromium.org> Signed-off-by: Hans de Goede <hdegoede@redhat.com> Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl>
-rw-r--r--drivers/media/usb/uvc/uvc_v4l2.c36
-rw-r--r--drivers/media/usb/uvc/uvcvideo.h4
2 files changed, 28 insertions, 12 deletions
diff --git a/drivers/media/usb/uvc/uvc_v4l2.c b/drivers/media/usb/uvc/uvc_v4l2.c
index 22886b47d81c..1d5be045d04e 100644
--- a/drivers/media/usb/uvc/uvc_v4l2.c
+++ b/drivers/media/usb/uvc/uvc_v4l2.c
@@ -26,6 +26,27 @@
#include "uvcvideo.h"
+int uvc_pm_get(struct uvc_device *dev)
+{
+ int ret;
+
+ ret = usb_autopm_get_interface(dev->intf);
+ if (ret)
+ return ret;
+
+ ret = uvc_status_get(dev);
+ if (ret)
+ usb_autopm_put_interface(dev->intf);
+
+ return ret;
+}
+
+void uvc_pm_put(struct uvc_device *dev)
+{
+ uvc_status_put(dev);
+ usb_autopm_put_interface(dev->intf);
+}
+
static int uvc_acquire_privileges(struct uvc_fh *handle);
static int uvc_control_add_xu_mapping(struct uvc_video_chain *chain,
@@ -642,20 +663,13 @@ static int uvc_v4l2_open(struct file *file)
stream = video_drvdata(file);
uvc_dbg(stream->dev, CALLS, "%s\n", __func__);
- ret = usb_autopm_get_interface(stream->dev->intf);
- if (ret < 0)
- return ret;
-
/* Create the device handle. */
handle = kzalloc(sizeof(*handle), GFP_KERNEL);
- if (handle == NULL) {
- usb_autopm_put_interface(stream->dev->intf);
+ if (!handle)
return -ENOMEM;
- }
- ret = uvc_status_get(stream->dev);
+ ret = uvc_pm_get(stream->dev);
if (ret) {
- usb_autopm_put_interface(stream->dev->intf);
kfree(handle);
return ret;
}
@@ -690,9 +704,7 @@ static int uvc_v4l2_release(struct file *file)
kfree(handle);
file->private_data = NULL;
- uvc_status_put(stream->dev);
-
- usb_autopm_put_interface(stream->dev->intf);
+ uvc_pm_put(stream->dev);
return 0;
}
diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvideo.h
index 5ceb01e7831a..b9f8eb62ba1d 100644
--- a/drivers/media/usb/uvc/uvcvideo.h
+++ b/drivers/media/usb/uvc/uvcvideo.h
@@ -768,6 +768,10 @@ void uvc_status_suspend(struct uvc_device *dev);
int uvc_status_get(struct uvc_device *dev);
void uvc_status_put(struct uvc_device *dev);
+/* PM */
+int uvc_pm_get(struct uvc_device *dev);
+void uvc_pm_put(struct uvc_device *dev);
+
/* Controls */
extern const struct v4l2_subscribed_event_ops uvc_ctrl_sub_ev_ops;