From: Adam Baker <linux@baker-net.org.uk>
To: "Jean-Francois Moine" <moinejf@free.fr>
Cc: kilgota@banach.math.auburn.edu, linux-media@vger.kernel.org,
Alan Stern <stern@rowland.harvard.edu>
Subject: Re: [PATCH] Add support for sq905 based cameras to gspca
Date: Tue, 3 Feb 2009 22:09:43 +0000 [thread overview]
Message-ID: <200902032209.44133.linux@baker-net.org.uk> (raw)
In-Reply-To: <20090203202307.0ae074ec@free.fr>
On Tuesday 03 February 2009, Jean-Francois Moine wrote:
> Indeed, the problem is there! You must have only one process reading the
> webcam! I do not see how this can work with these 2 processes...
Although 2 processes are created only one ever gets used.
create_singlethread_workqueue would therefore be less wasteful but make no
other difference. Google searches for create_freezeable_workqueue bring up
suggestions to avoid it so I think I will although I guess we ought to check
at some point how well the camera copes with suspend while streaming.
At 19:53:31 Alan Stern wrote
> If a camera is unplugged while it is in use then
> waiting until close() is no good -- it will cause destroy_urbs() to
> pass a stale pointer to usb_buffer_free(). That's the reason for the
> oops.
I'd go further and suggest that gspca_disconnect should, after calling
destroy_urbs() do gspca_dev->dev = NULL; Any use of that pointer past that
point is a bug (the downside is that doing so would have turned the current
bug into a hard to spot memory leak).
At 03:37:35 Alan Stern wrote
> On Mon, 2 Feb 2009, Adam Baker wrote:
>> This shouldn't be a problem for sq905 (which doesn't use these URBs) or
>> isochronous cameras (which don't need to resubmit URBs) but the finepix
>> driver (the other supported bulk device) will need some careful
>> consideration to avoid a race between killing the URB and resubmitting it.
>
> You shouldn't need to take any special action. usb_kill_urb() solves
> these races for you; it guarantees not to return until the URB has been
> unlinked and the completion handler has finished, and it guarantees
> that attempts by the completion handler to resubmit the URB will fail.
The sq905 driver doesn't use the URBs provided by gspca, it uses
usb_control_msg and usb_bulk_msg which I presume do the right thing
internally. There would be a tiny window in between when it checks the
dev->streaming flag and when it sends a new USB msg for the disconnect to
occur and invalidate the dev pointer. That could be fixed by holding
gspca_dev->usb_lock in gspca_disconnect when it sets gspca_dev->present = 0.
That would also address the race between open and disconnect.
Unfortunately the finepix driver sometimes uses calls to schedule_delayed_work
in the completion handler which then makes the call to usb_submit_urb. Fixing
that will require someone with access to a suitable camera to test it
otherwise there is a significant risk of adding deadlocks. It already suffers
from this bug so we aren't making it worse.
Calling destroy_urbs from dev_close rather than gspca_disconnect could also
trigger the same bug on isochronous cameras. I haven't looked at them closely
but they probably also have the race between open and disconnect which taking
the lock in disconnect is likely to fix.
I'll do some testing and post a patch if it looks promising.
Adam
next prev parent reply other threads:[~2009-02-03 22:09 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-01-19 23:22 [PATCH] Add support for sq905 based cameras to gspca Adam Baker
2009-01-20 3:33 ` Alexey Klimov
2009-01-21 17:20 ` Jean-Francois Moine
2009-01-21 19:10 ` kilgota
2009-01-22 4:17 ` Why not to try to combine sq905 and sq kilgota
[not found] ` <200901272101.27451.linux@baker-net.org.uk>
[not found] ` <alpine.LNX.2.00.0901271543560.21122@banach.math.auburn.edu>
[not found] ` <200901272228.42610.linux@baker-net.org.uk>
[not found] ` <20090128113540.25536301@free.fr>
[not found] ` <alpine.LNX.2.00.0901281554500.22748@banach.math.auburn.edu>
[not found] ` <20090131203650.36369153@free.fr>
[not found] ` <alpine.LNX.2.00.0902022032230.1080@banach.math.auburn.edu>
2009-02-03 9:39 ` [PATCH] Add support for sq905 based cameras to gspca Jean-Francois Moine
2009-02-03 17:30 ` kilgota
2009-02-03 18:21 ` kilgota
2009-02-03 18:13 ` Jean-Francois Moine
2009-02-03 19:15 ` kilgota
2009-02-03 19:23 ` Jean-Francois Moine
2009-02-03 19:54 ` kilgota
2009-02-03 19:47 ` Jean-Francois Moine
2009-02-03 19:59 ` Alan Stern
2009-02-03 22:23 ` kilgota
2009-02-04 2:02 ` Alan Stern
2009-02-04 3:12 ` kilgota
2009-02-03 22:09 ` Adam Baker [this message]
2009-02-03 22:28 ` kilgota
2009-02-04 1:59 ` Alan Stern
2009-02-04 2:33 ` Andy Walls
2009-02-04 21:38 ` Adam Baker
2009-02-04 22:31 ` kilgota
2009-02-04 22:34 ` Adam Baker
2009-02-04 22:53 ` kilgota
2009-02-04 23:09 ` kilgota
2009-02-03 19:42 ` kilgota
2009-02-03 19:53 ` Alan Stern
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=200902032209.44133.linux@baker-net.org.uk \
--to=linux@baker-net.org.uk \
--cc=kilgota@banach.math.auburn.edu \
--cc=linux-media@vger.kernel.org \
--cc=moinejf@free.fr \
--cc=stern@rowland.harvard.edu \
/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