From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: Guennadi Liakhovetski <g.liakhovetski@gmx.de>
Cc: Linux Media Mailing List <linux-media@vger.kernel.org>
Subject: Re: [PATCH v8 2/3] uvcvideo: send a control event when a Control Change interrupt arrives
Date: Tue, 17 Jul 2018 23:26:59 +0300 [thread overview]
Message-ID: <3815510.uz0YmiiscJ@avalon> (raw)
In-Reply-To: <alpine.DEB.2.20.1807120834060.24638@axis700.grange>
Hi Guennadi,
On Thursday, 12 July 2018 10:30:46 EEST Guennadi Liakhovetski wrote:
> On Thu, 12 Jul 2018, Laurent Pinchart wrote:
> > On Tuesday, 8 May 2018 18:07:43 EEST Guennadi Liakhovetski wrote:
> >> UVC defines a method of handling asynchronous controls, which sends a
> >> USB packet over the interrupt pipe. This patch implements support for
> >> such packets by sending a control event to the user. Since this can
> >> involve USB traffic and, therefore, scheduling, this has to be done
> >> in a work queue.
> >>
> >> Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@intel.com>
> >> ---
> >>
> >> v8:
> >>
> >> * avoid losing events by delaying the status URB resubmission until
> >> after completion of the current event
> >> * extract control value calculation into __uvc_ctrl_get_value()
> >> * do not proactively return EBUSY if the previous control hasn't
> >> completed yet, let the camera handle such cases
> >> * multiple cosmetic changes
> >>
> >> drivers/media/usb/uvc/uvc_ctrl.c | 166 ++++++++++++++++++++++++-------
> >> drivers/media/usb/uvc/uvc_status.c | 112 ++++++++++++++++++++++---
> >> drivers/media/usb/uvc/uvc_v4l2.c | 4 +-
> >> drivers/media/usb/uvc/uvcvideo.h | 15 +++-
> >> include/uapi/linux/uvcvideo.h | 2 +
> >> 5 files changed, 255 insertions(+), 44 deletions(-)
> >>
> >> diff --git a/drivers/media/usb/uvc/uvc_ctrl.c
> >> b/drivers/media/usb/uvc/uvc_ctrl.c index 2a213c8..796f86a 100644
> >> --- a/drivers/media/usb/uvc/uvc_ctrl.c
> >> +++ b/drivers/media/usb/uvc/uvc_ctrl.c
>
> [snip]
>
> >> +static void uvc_ctrl_status_event_work(struct work_struct *work)
> >> +{
> >> + struct uvc_device *dev = container_of(work, struct uvc_device,
> >> + async_ctrl.work);
> >> + struct uvc_ctrl_work *w = &dev->async_ctrl;
> >> + struct uvc_control_mapping *mapping;
> >> + struct uvc_control *ctrl = w->ctrl;
> >> + unsigned int i;
> >> + int ret;
> >> +
> >> + mutex_lock(&w->chain->ctrl_mutex);
> >> +
> >> + list_for_each_entry(mapping, &ctrl->info.mappings, list) {
> >> + s32 value = __uvc_ctrl_get_value(mapping, w->data);
> >> +
> >> + /*
> >> + * So far none of the auto-update controls in the uvc_ctrls[]
> >> + * table is mapped to a V4L control with slaves in the
> >> + * uvc_ctrl_mappings[] list, so slave controls so far never have
> >> + * handle == NULL, but this can change in the future
> >> + */
> >> + for (i = 0; i < ARRAY_SIZE(mapping->slave_ids); ++i) {
> >> + if (!mapping->slave_ids[i])
> >> + break;
> >> +
> >> + __uvc_ctrl_send_slave_event(ctrl->handle, w->chain,
> >> + ctrl, mapping->slave_ids[i]);
> >> + }
> >> +
> >> + uvc_ctrl_send_event(ctrl->handle, ctrl, mapping, value,
> >> + V4L2_EVENT_CTRL_CH_VALUE);
> >> + }
> >> +
> >> + mutex_unlock(&w->chain->ctrl_mutex);
> >> +
> >> + ctrl->handle = NULL;
> >
> > Can't this race with a uvc_ctrl_set() call, resulting in ctrl->handle
> > being NULL after the control gets set ?
>
> Right, it's better to set .handle to NULL before sending events. Something
> like
>
> mutex_lock();
>
> handle = ctrl->handle;
> ctrl->handle = NULL;
>
> list_for_each_entry() {
> ...
> uvc_ctrl_send_event(handle,...);
> }
>
> mutex_unlock();
>
> ?
I think you also have to take the same lock in the uvc_ctrl_set() function to
fix the problem, otherwise the ctrl->handle = NULL line could still be
executed after the ctrl->handle assignment in uvc_ctrl_set(), resulting in
ctrl->handle being NULL while the control is being set.
> >> + /* Resubmit the URB. */
> >> + w->urb->interval = dev->int_ep->desc.bInterval;
> >> + ret = usb_submit_urb(w->urb, GFP_KERNEL);
> >> + if (ret < 0)
> >> + uvc_printk(KERN_ERR, "Failed to resubmit status URB (%d).\n",
> >> + ret);
> >> +}
[snip]
> >> diff --git a/drivers/media/usb/uvc/uvc_status.c
> >> b/drivers/media/usb/uvc/uvc_status.c index 7b71041..a0f2fea 100644
> >> --- a/drivers/media/usb/uvc/uvc_status.c
> >> +++ b/drivers/media/usb/uvc/uvc_status.c
[snip]
> >> +static struct uvc_control *uvc_event_find_ctrl(struct uvc_device *dev,
> >> + const struct uvc_control_status *status,
> >> + struct uvc_video_chain **chain)
> >> +{
> >> + list_for_each_entry((*chain), &dev->chains, list) {
> >> + struct uvc_entity *entity;
> >> + struct uvc_control *ctrl;
> >> +
> >> + list_for_each_entry(entity, &(*chain)->entities, chain) {
> >> + if (entity->id != status->bOriginator)
> >> + continue;
> >> +
> >> + ctrl = uvc_event_entity_find_ctrl(entity,
> >> + status->bSelector);
> >> + if (ctrl && (!ctrl->handle ||
> >> + ctrl->handle->chain == *chain))
> >
> > I'm afraid I still don't understand why you need the chain check :-(
> > Unless I'm mistaken, ctrl->handle is set in uvc_ctrl_set(), where the
> > control is looked up from the chain corresponding to handle->chain. How
> > can the check be false here ?
>
> I think you're right, the bOriginator check should be enough.
>
> > Those are my two major concerns. Apart from that I have other small
> > concerns that I propose addressing myself to avoid further delays. I've
> > been slow enough when it comes to reviewing this series, if we can clear
> > the two issues above, I'll handle the rest.
>
> Once I get your review of patch #3, I'll fix these two issues and
> resubmit, so you can also tell me your "minor concerns," since I'll be
> resubmitting anyway.
Do you mind if I send them as a diff on top of your patch ? I'll of course add
explanations where they are needed.
> >> + return ctrl;
> >> + }
> >> + }
> >> +
> >> + return NULL;
> >> +}
[snip]
--
Regards,
Laurent Pinchart
next prev parent reply other threads:[~2018-07-17 21:00 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-05-08 15:07 [PATCH v8 0/3] uvcvideo: asynchronous controls Guennadi Liakhovetski
2018-05-08 15:07 ` [PATCH v8 1/3] uvcvideo: remove a redundant check Guennadi Liakhovetski
2018-07-10 22:18 ` Laurent Pinchart
2018-05-08 15:07 ` [PATCH v8 2/3] uvcvideo: send a control event when a Control Change interrupt arrives Guennadi Liakhovetski
2018-07-11 23:25 ` Laurent Pinchart
2018-07-12 7:30 ` Guennadi Liakhovetski
2018-07-17 13:07 ` Guennadi Liakhovetski
2018-07-17 20:26 ` Laurent Pinchart [this message]
2018-07-17 21:30 ` Guennadi Liakhovetski
2018-07-17 23:44 ` Laurent Pinchart
2018-07-18 6:55 ` Guennadi Liakhovetski
2018-07-25 17:10 ` Laurent Pinchart
2018-07-25 17:21 ` Guennadi Liakhovetski
2018-07-25 19:13 ` Laurent Pinchart
2018-07-26 7:03 ` Guennadi Liakhovetski
2018-07-26 8:17 ` [PATCH v9] " Guennadi Liakhovetski
2018-07-26 12:24 ` Laurent Pinchart
2018-07-26 12:42 ` Guennadi Liakhovetski
2018-07-25 17:25 ` [PATCH v8 2/3] " Laurent Pinchart
2018-07-25 19:06 ` Laurent Pinchart
2018-05-08 15:07 ` [PATCH v8 3/3] uvcvideo: handle control pipe protocol STALLs Guennadi Liakhovetski
2018-07-17 20:58 ` Laurent Pinchart
2018-07-17 23:17 ` Laurent Pinchart
2018-05-31 21:03 ` [PATCH v8 0/3] uvcvideo: asynchronous controls Guennadi Liakhovetski
2018-06-22 14:27 ` Guennadi Liakhovetski
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=3815510.uz0YmiiscJ@avalon \
--to=laurent.pinchart@ideasonboard.com \
--cc=g.liakhovetski@gmx.de \
--cc=linux-media@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox