From: Hans de Goede <hdegoede@redhat.com>
To: Hans Verkuil <hverkuil@xs4all.nl>
Cc: linux-media@vger.kernel.org, Hans Verkuil <hans.verkuil@cisco.com>
Subject: Re: [RFCv2 PATCH 13/17] gspca: switch to V4L2 core locking, except for the buffer queuing ioctls.
Date: Sun, 06 May 2012 19:58:10 +0200 [thread overview]
Message-ID: <4FA6BBB2.9010505@redhat.com> (raw)
In-Reply-To: <201205061751.03303.hverkuil@xs4all.nl>
Hi,
On 05/06/2012 05:51 PM, Hans Verkuil wrote:
> On Sun May 6 2012 17:25:55 Hans de Goede wrote:
<snip snip>
>> Notice that usb_lock is unlocked before video_unregister_device gets called,
>> which means that any ioctl or other fops waiting for usb_lock can run
>> before video_unregister_device runs, and thus before they are protected
>> against being called on an disconnected device by the
>> video_is_registered checks in v4l2-dev.
>
> True, good catch, I missed that one.
>
>> Unfortunately simply moving the unlock down won't work, because if there
>> are no open file handles referencing the device, then the memory
>> referenced by gspca_dev will be free-ed after the video_unregister_device
>> call.
>
> What you should do (refer to the disconnect implementation in radio/dsbr100.c)
> is to use the release callback of struct v4l2_device instead. That way the
> memory will be released after you call v4l2_device_put() as the last line in
> the disconnect(). The advantage of using the v4l2_device release callback is
> that it also works if you have more than one video/radio/vbi node. Only when
> the very last user of the very last node exits will the release be called.
Better solution, I'll adapt your patch to use this solution, merging in
the necessary changes.
<snip snip>
>>> @@ -2009,11 +1883,9 @@ static int vidioc_dqbuf(struct file *file, void *priv,
>>> gspca_dev->fr_o = (i + 1) % GSPCA_MAX_FRAMES;
>>>
>>> if (gspca_dev->sd_desc->dq_callback) {
>>> - mutex_lock(&gspca_dev->usb_lock);
>>> gspca_dev->usb_err = 0;
>>> if (gspca_dev->present)
>>> gspca_dev->sd_desc->dq_callback(gspca_dev);
>>> - mutex_unlock(&gspca_dev->usb_lock);
>>> }
>>>
>>> frame->v4l2_buf.flags&= ~V4L2_BUF_FLAG_DONE;
>>
>> You cannot remove the locking here, as dq_callback expects to be
>> called with the usb-lock locked.
>>
>> Since usb-lock now is the device lock and thus gets locked before
>> the queue_lock, we cannot simply drop this chunk. Instead I've
>> moved the dq_callback to the end of vidioc_dqbuf, so after the
>> stream_lock has been released (there is no reason to have
>> the stream_lock hold when calling the dq_callback).
>>
>> The dq_callback is used to do camera control adjustments which
>> need to be done after every X frames, and which cannot be done
>> from the isoc frame interrupts since they should not be done under
>> interrupt. When the drivers using dq_callback are converted to the
>> control framework, they will likely end up calling v4l2_ctrl_s_ctrl
>> from the dq_callback.
>
> Can't dq_callback be called at the end of the function?
Right, if you look at the new version of the patch I had attached,
you will see that is actually what I did, which is what I tried to
explain with: "Instead I've moved the dq_callback to the end of
vidioc_dqbuf, so after the stream_lock has been released (there
is no reason to have the stream_lock hold when calling the dq_callback)".
> After the
> mutex_unlock(&queue_lock)? There we can take the usb_lock, call dq_callback
> and unlock usb_lock again:
>
> out:
> mutex_unlock(&gspca_dev->queue_lock);
> if (!ret&& gspca_dev->sd_desc->dq_callback) {
> if (mutex_lock_interruptible(&gspca_dev->usb_lock))
> return -ERESTARTSYS;
> gspca_dev->usb_err = 0;
> gspca_dev->sd_desc->dq_callback(gspca_dev);
> mutex_unlock(&gspca_dev->usb_lock);
> }
> return ret;
>
Right, almost exactly what I've except that you're missing a gscpa_dev->present
check after taking the lock.
Regards,
Hans
next prev parent reply other threads:[~2012-05-06 17:58 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-05-06 12:28 [RFCv2 PATCH 00/17] gspca: allow use of control framework and other fixes Hans Verkuil
2012-05-06 12:28 ` [RFCv2 PATCH 01/17] v4l2-dev: make it possible to skip locking for selected ioctls Hans Verkuil
2012-05-06 12:28 ` [RFCv2 PATCH 02/17] v4l2-framework.txt: add paragraph on driver locking and the control framework Hans Verkuil
2012-05-06 12:28 ` [RFCv2 PATCH 03/17] gspca: allow subdrivers to use " Hans Verkuil
2012-05-06 12:28 ` [RFCv2 PATCH 04/17] gspca: use video_drvdata(file) instead of file->private_data Hans Verkuil
2012-05-06 12:28 ` [RFCv2 PATCH 05/17] gscpa: use v4l2_fh and add G/S_PRIORITY support Hans Verkuil
2012-05-06 12:28 ` [RFCv2 PATCH 06/17] gspca: add support for control events Hans Verkuil
2012-05-06 12:28 ` [RFCv2 PATCH 07/17] gspca: fix querycap and incorrect return codes Hans Verkuil
2012-05-06 12:28 ` [RFCv2 PATCH 08/17] gspca: fix locking issues related to suspend/resume Hans Verkuil
2012-05-06 12:28 ` [RFCv2 PATCH 09/17] gspca_zc3xx: Fix setting of jpeg quality while streaming Hans Verkuil
2012-05-06 12:28 ` [RFCv2 PATCH 10/17] gspca_zc3xx: Fix JPEG quality setting code Hans Verkuil
2012-05-06 12:28 ` [RFCv2 PATCH 11/17] gscpa_zc3xx: Always automatically adjust BRC as needed Hans Verkuil
2012-05-06 12:28 ` [RFCv2 PATCH 12/17] gscpa_zc3xx: Disable the highest quality setting as it is not usable Hans Verkuil
2012-05-06 12:28 ` [RFCv2 PATCH 13/17] gspca: switch to V4L2 core locking, except for the buffer queuing ioctls Hans Verkuil
2012-05-06 15:25 ` Hans de Goede
2012-05-06 15:51 ` Hans Verkuil
2012-05-06 17:58 ` Hans de Goede [this message]
2012-05-06 12:28 ` [RFCv2 PATCH 14/17] gspca-zc3xx: convert to the control framework Hans Verkuil
2012-05-06 12:28 ` [RFCv2 PATCH 15/17] gcpca-sn9c20x: " Hans Verkuil
2012-05-06 12:28 ` [RFCv2 PATCH 16/17] gspca-stv06xx: " Hans Verkuil
2012-05-06 12:28 ` [RFCv2 PATCH 17/17] gspca-mars: " Hans Verkuil
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=4FA6BBB2.9010505@redhat.com \
--to=hdegoede@redhat.com \
--cc=hans.verkuil@cisco.com \
--cc=hverkuil@xs4all.nl \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.