Skip to content

Commit 2f10157

Browse files
ribaldahverkuil
authored andcommitted
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 <[email protected]> Signed-off-by: Ricardo Ribalda <[email protected]> Message-ID: <[email protected]> Signed-off-by: Hans de Goede <[email protected]> Signed-off-by: Hans Verkuil <[email protected]>
1 parent 14f6e20 commit 2f10157

File tree

2 files changed

+28
-12
lines changed

2 files changed

+28
-12
lines changed

drivers/media/usb/uvc/uvc_v4l2.c

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,27 @@
2626

2727
#include "uvcvideo.h"
2828

29+
int uvc_pm_get(struct uvc_device *dev)
30+
{
31+
int ret;
32+
33+
ret = usb_autopm_get_interface(dev->intf);
34+
if (ret)
35+
return ret;
36+
37+
ret = uvc_status_get(dev);
38+
if (ret)
39+
usb_autopm_put_interface(dev->intf);
40+
41+
return ret;
42+
}
43+
44+
void uvc_pm_put(struct uvc_device *dev)
45+
{
46+
uvc_status_put(dev);
47+
usb_autopm_put_interface(dev->intf);
48+
}
49+
2950
static int uvc_acquire_privileges(struct uvc_fh *handle);
3051

3152
static int uvc_control_add_xu_mapping(struct uvc_video_chain *chain,
@@ -642,20 +663,13 @@ static int uvc_v4l2_open(struct file *file)
642663
stream = video_drvdata(file);
643664
uvc_dbg(stream->dev, CALLS, "%s\n", __func__);
644665

645-
ret = usb_autopm_get_interface(stream->dev->intf);
646-
if (ret < 0)
647-
return ret;
648-
649666
/* Create the device handle. */
650667
handle = kzalloc(sizeof(*handle), GFP_KERNEL);
651-
if (handle == NULL) {
652-
usb_autopm_put_interface(stream->dev->intf);
668+
if (!handle)
653669
return -ENOMEM;
654-
}
655670

656-
ret = uvc_status_get(stream->dev);
671+
ret = uvc_pm_get(stream->dev);
657672
if (ret) {
658-
usb_autopm_put_interface(stream->dev->intf);
659673
kfree(handle);
660674
return ret;
661675
}
@@ -690,9 +704,7 @@ static int uvc_v4l2_release(struct file *file)
690704
kfree(handle);
691705
file->private_data = NULL;
692706

693-
uvc_status_put(stream->dev);
694-
695-
usb_autopm_put_interface(stream->dev->intf);
707+
uvc_pm_put(stream->dev);
696708
return 0;
697709
}
698710

drivers/media/usb/uvc/uvcvideo.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -768,6 +768,10 @@ void uvc_status_suspend(struct uvc_device *dev);
768768
int uvc_status_get(struct uvc_device *dev);
769769
void uvc_status_put(struct uvc_device *dev);
770770

771+
/* PM */
772+
int uvc_pm_get(struct uvc_device *dev);
773+
void uvc_pm_put(struct uvc_device *dev);
774+
771775
/* Controls */
772776
extern const struct v4l2_subscribed_event_ops uvc_ctrl_sub_ev_ops;
773777

0 commit comments

Comments
 (0)