Skip to contentSkip to conversation

Control events support for uvcvideo

GIT PULL Laurent Pinchart 2 participants 6 messages Apr 29, 2012 – Apr 30, 2012 Media (V4L/DVB)

lore
Share & tools
lore
#0 lore raw

Hi Mauro,

The following changes since commit bcb2cf6e0bf033d79821c89e5ccb328bfbd44907:

[media] ngene: remove an unneeded condition (2012-04-26 15:29:23 -0300)

are available in the git repository at:
git://linuxtv.org/pinchartl/uvcvideo.git uvcvideo-events

Hans de Goede (10):
media/radio: use v4l2_ctrl_subscribe_event where possible
v4l2-event: Add v4l2_subscribed_event_ops
v4l2-ctrls: Use v4l2_subscribed_event_ops
uvcvideo: Fix a "ignoring return value of ‘__clear_user’" warning
uvcvideo: Refactor uvc_ctrl_get and query
uvcvideo: Move __uvc_ctrl_get() up
uvcvideo: Add support for control events
uvcvideo: Properly report the inactive flag for inactive controls
uvcvideo: Send control change events for slave ctrls when the master changes
uvcvideo: Drop unused ctrl member from struct uvc_control_mapping

 Documentation/video4linux/v4l2-framework.txt |   28 ++-
 drivers/media/radio/radio-isa.c              |   10 +-
 drivers/media/radio/radio-keene.c            |   14 +-
 drivers/media/video/ivtv/ivtv-ioctl.c        |    3 +-
 drivers/media/video/omap3isp/ispccdc.c       |    2 +-
 drivers/media/video/omap3isp/ispstat.c       |    2 +-
 drivers/media/video/uvc/uvc_ctrl.c           |  320 +++++++++++++++++++++----
 drivers/media/video/uvc/uvc_v4l2.c           |   46 +++-
 drivers/media/video/uvc/uvcvideo.h           |   26 ++-
 drivers/media/video/v4l2-ctrls.c             |   58 ++++-
 drivers/media/video/v4l2-event.c             |   71 +++---
 drivers/usb/gadget/uvc_v4l2.c                |    2 +-
 include/media/v4l2-ctrls.h                   |    7 +-
 include/media/v4l2-event.h                   |   24 ++-
 14 files changed, 456 insertions(+), 157 deletions(-)
Signature · 3 lines
Regards,

Laurent Pinchart
#1 lore raw

Hi Laurent,

I know I am very late with this, but I looked through the event/control core changes and I found a locking bug there. I didn't have a chance to review the patch series when HdG posted it earlier this month, so my apologies for coming up with this only now.

The problem is in v4l2-ctrls.c:

drivers/media/video/v4l2-ctrls.c +1 -3
index 7023e6d..2a44355 100644
@@ -2381,10 +2381,22 @@ int v4l2_ctrl_s_ctrl(struct v4l2_ctrl *ctrl, s32 val)
 }
 EXPORT_SYMBOL(v4l2_ctrl_s_ctrl);
 
-void v4l2_ctrl_add_event(struct v4l2_ctrl *ctrl,
-                               struct v4l2_subscribed_event *sev)
+static int v4l2_ctrl_add_event(struct v4l2_subscribed_event *sev)
 {
-       v4l2_ctrl_lock(ctrl);
 

This lock...

+       struct v4l2_ctrl_handler *hdl = sev->fh->ctrl_handler;
+       struct v4l2_ctrl_ref *ref;
+       struct v4l2_ctrl *ctrl;
+       int ret = 0;

+
+ mutex_lock(&hdl->lock);

...and this lock are not necessarily the same. If the control was from a subdevice then they will be different. This doesn't happen in uvc, but it will in other drivers.

+
+ ref = find_ref(hdl, sev->id);

The right approach is to use v4l2_ctrl_find here and then call v4l2_ctrl_lock(ctrl), just as was done in the original code.

+ if (!ref) {
+ ret = -EINVAL;
+ goto leave;
+ }
+ ctrl = ref->ctrl;
+

        list_add_tail(&sev->node, &ctrl->ev_subs);
        if (ctrl->type != V4L2_CTRL_TYPE_CTRL_CLASS &&
            (sev->flags & V4L2_EVENT_SUB_FL_SEND_INITIAL)) {
@@ -2396,18 +2408,42 @@ void v4l2_ctrl_add_event(struct v4l2_ctrl *ctrl,
                fill_event(&ev, ctrl, changes);
                v4l2_event_queue_fh(sev->fh, &ev);
        }

- v4l2_ctrl_unlock(ctrl);
+leave:
+ mutex_unlock(&hdl->lock);
+ return ret;
}
-EXPORT_SYMBOL(v4l2_ctrl_add_event);

-void v4l2_ctrl_del_event(struct v4l2_ctrl *ctrl,
- struct v4l2_subscribed_event *sev)
+static void v4l2_ctrl_del_event(struct v4l2_subscribed_event *sev)
{
- v4l2_ctrl_lock(ctrl);
+ struct v4l2_ctrl_handler *hdl = sev->fh->ctrl_handler;
+
+ mutex_lock(&hdl->lock);

Same problem here.

        list_del(&sev->node);

- v4l2_ctrl_unlock(ctrl);
+ mutex_unlock(&hdl->lock);
}
-EXPORT_SYMBOL(v4l2_ctrl_del_event);

So the code should be:

static int v4l2_ctrl_add_event(struct v4l2_subscribed_event *sev)

{
		struct v4l2_ctrl *ctrl = v4l2_ctrl_find(sev->fh->ctrl_handler, sev->id);

		if (ctrl == NULL)
				return -EINVAL;
        v4l2_ctrl_lock(ctrl);
        list_add_tail(&sev->node, &ctrl->ev_subs);
        if (ctrl->type != V4L2_CTRL_TYPE_CTRL_CLASS &&
            (sev->flags & V4L2_EVENT_SUB_FL_SEND_INITIAL)) {
                struct v4l2_event ev;
                u32 changes = V4L2_EVENT_CTRL_CH_FLAGS;

                if (!(ctrl->flags & V4L2_CTRL_FLAG_WRITE_ONLY))
                        changes |= V4L2_EVENT_CTRL_CH_VALUE;
                fill_event(&ev, ctrl, changes);
                v4l2_event_queue_fh(sev->fh, &ev);
        }
        v4l2_ctrl_unlock(ctrl);
		return 0;
}

and:

static void v4l2_ctrl_del_event(struct v4l2_subscribed_event *sev)

{
		struct v4l2_ctrl *ctrl = v4l2_ctrl_find(sev->fh->ctrl_handler, sev->id);

        v4l2_ctrl_lock(ctrl);
        list_del(&sev->node);
        v4l2_ctrl_unlock(ctrl);
}

Regards,

Hans

Quoted 38 lines · On Sunday, April 29, 2012 19:59:01 Laurent Pinchart wrote:

Hi Mauro,

The following changes since commit bcb2cf6e0bf033d79821c89e5ccb328bfbd44907:

[media] ngene: remove an unneeded condition (2012-04-26 15:29:23 -0300)

are available in the git repository at:
git://linuxtv.org/pinchartl/uvcvideo.git uvcvideo-events

Hans de Goede (10):
media/radio: use v4l2_ctrl_subscribe_event where possible
v4l2-event: Add v4l2_subscribed_event_ops
v4l2-ctrls: Use v4l2_subscribed_event_ops
uvcvideo: Fix a "ignoring return value of ‘__clear_user’" warning
uvcvideo: Refactor uvc_ctrl_get and query
uvcvideo: Move __uvc_ctrl_get() up
uvcvideo: Add support for control events
uvcvideo: Properly report the inactive flag for inactive controls
uvcvideo: Send control change events for slave ctrls when the master changes
uvcvideo: Drop unused ctrl member from struct uvc_control_mapping

 Documentation/video4linux/v4l2-framework.txt |   28 ++-
 drivers/media/radio/radio-isa.c              |   10 +-
 drivers/media/radio/radio-keene.c            |   14 +-
 drivers/media/video/ivtv/ivtv-ioctl.c        |    3 +-
 drivers/media/video/omap3isp/ispccdc.c       |    2 +-
 drivers/media/video/omap3isp/ispstat.c       |    2 +-
 drivers/media/video/uvc/uvc_ctrl.c           |  320 +++++++++++++++++++++----
 drivers/media/video/uvc/uvc_v4l2.c           |   46 +++-
 drivers/media/video/uvc/uvcvideo.h           |   26 ++-
 drivers/media/video/v4l2-ctrls.c             |   58 ++++-
 drivers/media/video/v4l2-event.c             |   71 +++---
 drivers/usb/gadget/uvc_v4l2.c                |    2 +-
 include/media/v4l2-ctrls.h                   |    7 +-
 include/media/v4l2-event.h                   |   24 ++-
 14 files changed, 456 insertions(+), 157 deletions(-)
#2 lore raw

Hi Hans,

Quoted 6 lines · On Monday 30 April 2012 08:30:39 Hans Verkuil wrote:

Hi Laurent,

I know I am very late with this, but I looked through the event/control core changes and I found a locking bug there. I didn't have a chance to review the patch series when HdG posted it earlier this month, so my apologies for coming up with this only now.

No worries. Thank you for catching the bug, I'll send a new pull request.

Signature · 3 lines
Regards,

Laurent Pinchart
#3 lore raw

[GIT PULL for v3.5] (v2) Control events support for uvcvideo

In reply to Laurent Pinchart

Hi Mauro,

A locking bug was present in the previous pull request. Please ignore it and pull this one instead.

The following changes since commit bcb2cf6e0bf033d79821c89e5ccb328bfbd44907:

[media] ngene: remove an unneeded condition (2012-04-26 15:29:23 -0300)

are available in the git repository at:
git://linuxtv.org/pinchartl/uvcvideo.git uvcvideo-events

Hans de Goede (10):
media/radio: use v4l2_ctrl_subscribe_event where possible
v4l2-event: Add v4l2_subscribed_event_ops
v4l2-ctrls: Use v4l2_subscribed_event_ops
uvcvideo: Fix a "ignoring return value of ‘__clear_user’" warning
uvcvideo: Refactor uvc_ctrl_get and query
uvcvideo: Move __uvc_ctrl_get() up
uvcvideo: Add support for control events
uvcvideo: Properly report the inactive flag for inactive controls
uvcvideo: Send control change events for slave ctrls when the master changes
uvcvideo: Drop unused ctrl member from struct uvc_control_mapping

 Documentation/video4linux/v4l2-framework.txt |   28 ++-
 drivers/media/radio/radio-isa.c              |   10 +-
 drivers/media/radio/radio-keene.c            |   14 +-
 drivers/media/video/ivtv/ivtv-ioctl.c        |    3 +-
 drivers/media/video/omap3isp/ispccdc.c       |    2 +-
 drivers/media/video/omap3isp/ispstat.c       |    2 +-
 drivers/media/video/uvc/uvc_ctrl.c           |  320 ++++++++++++++++++++++----
 drivers/media/video/uvc/uvc_v4l2.c           |   46 +++-
 drivers/media/video/uvc/uvcvideo.h           |   26 ++-
 drivers/media/video/v4l2-ctrls.c             |   47 +++-
 drivers/media/video/v4l2-event.c             |   71 +++---
 drivers/usb/gadget/uvc_v4l2.c                |    2 +-
 include/media/v4l2-ctrls.h                   |    7 +-
 include/media/v4l2-event.h                   |   24 ++-
 14 files changed, 447 insertions(+), 155 deletions(-)
Signature · 3 lines
Regards,

Laurent Pinchart
#4 lore raw

Re: [GIT PULL for v3.5] (v2) Control events support for uvcvideo

Hi Laurent!

Quoted 4 lines · On Monday 30 April 2012 11:43:10 Laurent Pinchart wrote:

Hi Mauro,

A locking bug was present in the previous pull request. Please ignore it and pull this one instead.

I hate to say it, but while you did update v4l2_ctrl_add_event, you forgot to update v4l2_ctrl_del_event as well. That one still has the same locking issue...

Time for a v3 :-)

Regards,

Hans

Quoted 37 lines

The following changes since commit
bcb2cf6e0bf033d79821c89e5ccb328bfbd44907:

[media] ngene: remove an unneeded condition (2012-04-26 15:29:23 -0300)

are available in the git repository at:
git://linuxtv.org/pinchartl/uvcvideo.git uvcvideo-events

Hans de Goede (10):
media/radio: use v4l2_ctrl_subscribe_event where possible
v4l2-event: Add v4l2_subscribed_event_ops
v4l2-ctrls: Use v4l2_subscribed_event_ops
uvcvideo: Fix a "ignoring return value of ‘__clear_user’" warning
uvcvideo: Refactor uvc_ctrl_get and query
uvcvideo: Move __uvc_ctrl_get() up
uvcvideo: Add support for control events
uvcvideo: Properly report the inactive flag for inactive controls
uvcvideo: Send control change events for slave ctrls when the master
changes uvcvideo: Drop unused ctrl member from struct uvc_control_mapping

 Documentation/video4linux/v4l2-framework.txt |   28 ++-
 drivers/media/radio/radio-isa.c              |   10 +-
 drivers/media/radio/radio-keene.c            |   14 +-
 drivers/media/video/ivtv/ivtv-ioctl.c        |    3 +-
 drivers/media/video/omap3isp/ispccdc.c       |    2 +-
 drivers/media/video/omap3isp/ispstat.c       |    2 +-
 drivers/media/video/uvc/uvc_ctrl.c           |  320
++++++++++++++++++++++---- drivers/media/video/uvc/uvc_v4l2.c           | 
 46 +++-
 drivers/media/video/uvc/uvcvideo.h           |   26 ++-
 drivers/media/video/v4l2-ctrls.c             |   47 +++-
 drivers/media/video/v4l2-event.c             |   71 +++---
 drivers/usb/gadget/uvc_v4l2.c                |    2 +-
 include/media/v4l2-ctrls.h                   |    7 +-
 include/media/v4l2-event.h                   |   24 ++-
 14 files changed, 447 insertions(+), 155 deletions(-)
#5 lore raw

[GIT PULL for v3.5] (v3) Control events support for uvcvideo

Hi Hans,

Quoted 9 lines · On Monday 30 April 2012 11:49:54 Hans Verkuil wrote:
Quoted 4 lines · On Monday 30 April 2012 11:43:10 Laurent Pinchart wrote:

Hi Mauro,

A locking bug was present in the previous pull request. Please ignore it and pull this one instead.

I hate to say it, but while you did update v4l2_ctrl_add_event, you forgot to update v4l2_ctrl_del_event as well. That one still has the same locking issue...

If it wasn't noon already I'd blame it on not having woken up completely :-)

Quoted 1 line

Time for a v3 :-)

Here it is.

Mauro, could you please pull the following ? Sorry for the noise.

The following changes since commit bcb2cf6e0bf033d79821c89e5ccb328bfbd44907:

[media] ngene: remove an unneeded condition (2012-04-26 15:29:23 -0300)

are available in the git repository at:
git://linuxtv.org/pinchartl/uvcvideo.git uvcvideo-events

Hans de Goede (10):
media/radio: use v4l2_ctrl_subscribe_event where possible
v4l2-event: Add v4l2_subscribed_event_ops
v4l2-ctrls: Use v4l2_subscribed_event_ops
uvcvideo: Fix a "ignoring return value of ‘__clear_user’" warning
uvcvideo: Refactor uvc_ctrl_get and query
uvcvideo: Move __uvc_ctrl_get() up
uvcvideo: Add support for control events
uvcvideo: Properly report the inactive flag for inactive controls
uvcvideo: Send control change events for slave ctrls when the master changes
uvcvideo: Drop unused ctrl member from struct uvc_control_mapping

 Documentation/video4linux/v4l2-framework.txt |   28 ++-
 drivers/media/radio/radio-isa.c              |   10 +-
 drivers/media/radio/radio-keene.c            |   14 +-
 drivers/media/video/ivtv/ivtv-ioctl.c        |    3 +-
 drivers/media/video/omap3isp/ispccdc.c       |    2 +-
 drivers/media/video/omap3isp/ispstat.c       |    2 +-
 drivers/media/video/uvc/uvc_ctrl.c           |  320 ++++++++++++++++++++++----
 drivers/media/video/uvc/uvc_v4l2.c           |   46 +++-
 drivers/media/video/uvc/uvcvideo.h           |   26 ++-
 drivers/media/video/v4l2-ctrls.c             |   41 +++-
 drivers/media/video/v4l2-event.c             |   71 +++---
 drivers/usb/gadget/uvc_v4l2.c                |    2 +-
 include/media/v4l2-ctrls.h                   |    7 +-
 include/media/v4l2-event.h                   |   24 ++-
 14 files changed, 443 insertions(+), 153 deletions(-)
Signature · 3 lines
Regards,

Laurent Pinchart