Skip to content

Commit a03e32e

Browse files
ribaldahverkuil
authored andcommitted
media: uvcvideo: Turn on the camera if V4L2_EVENT_SUB_FL_SEND_INITIAL
If we subscribe to an event with V4L2_EVENT_SUB_FL_SEND_INITIAL, the driver needs to report back some values that require the camera to be powered on. But VIDIOC_SUBSCRIBE_EVENT is not part of the ioctls that turn on the camera. We could unconditionally turn on the camera during VIDIOC_SUBSCRIBE_EVENT, but it is more efficient to turn it on only during V4L2_EVENT_SUB_FL_SEND_INITIAL, which we believe is not a common usecase. To avoid a list_del if uvc_pm_get() fails, we move list_add_tail to the end of the function. Reviewed-by: Hans de Goede <[email protected]> Fixes: d1b618e ("media: uvcvideo: Do not turn on the camera for some ioctls") Cc: [email protected] Reviewed-by: Laurent Pinchart <[email protected]> Signed-off-by: Ricardo Ribalda <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Hans de Goede <[email protected]> Signed-off-by: Hans Verkuil <[email protected]>
1 parent 7dd56c4 commit a03e32e

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

drivers/media/usb/uvc/uvc_ctrl.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2072,18 +2072,24 @@ static int uvc_ctrl_add_event(struct v4l2_subscribed_event *sev, unsigned elems)
20722072
goto done;
20732073
}
20742074

2075-
list_add_tail(&sev->node, &mapping->ev_subs);
20762075
if (sev->flags & V4L2_EVENT_SUB_FL_SEND_INITIAL) {
20772076
struct v4l2_event ev;
20782077
u32 changes = V4L2_EVENT_CTRL_CH_FLAGS;
20792078
s32 val = 0;
20802079

2080+
ret = uvc_pm_get(handle->chain->dev);
2081+
if (ret)
2082+
goto done;
2083+
20812084
if (uvc_ctrl_mapping_is_compound(mapping) ||
20822085
__uvc_ctrl_get(handle->chain, ctrl, mapping, &val) == 0)
20832086
changes |= V4L2_EVENT_CTRL_CH_VALUE;
20842087

20852088
uvc_ctrl_fill_event(handle->chain, &ev, ctrl, mapping, val,
20862089
changes);
2090+
2091+
uvc_pm_put(handle->chain->dev);
2092+
20872093
/*
20882094
* Mark the queue as active, allowing this initial event to be
20892095
* accepted.
@@ -2092,6 +2098,8 @@ static int uvc_ctrl_add_event(struct v4l2_subscribed_event *sev, unsigned elems)
20922098
v4l2_event_queue_fh(sev->fh, &ev);
20932099
}
20942100

2101+
list_add_tail(&sev->node, &mapping->ev_subs);
2102+
20952103
done:
20962104
mutex_unlock(&handle->chain->ctrl_mutex);
20972105
return ret;

0 commit comments

Comments
 (0)