From: Oliver Neukum <oliver@neukum.org>
To: Alan Stern <stern@rowland.harvard.edu>
Cc: Greg KH <gregkh@suse.de>,
stable@kernel.org, Rickard Bellini <rickard.bellini@ericsson.com>,
"linux-usb@vger.kernel.org" <linux-usb@vger.kernel.org>,
Torgny Johansson <torgny.johansson@ericsson.com>,
Kernel development list <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] Driver core: fix race in dev_driver_string
Date: Fri, 4 Dec 2009 22:18:11 +0100 [thread overview]
Message-ID: <200912042218.11410.oliver@neukum.org> (raw)
In-Reply-To: <Pine.LNX.4.44L0.0912041555430.3070-100000@iolanthe.rowland.org>
Am Freitag, 4. Dezember 2009 21:57:50 schrieb Alan Stern:
> On Fri, 4 Dec 2009, Oliver Neukum wrote:
> > > > 1. am I supposed to get a reference just so that I can use dev_err?
> > >
> > > No, you should already have a reference on the device when doing the
> > > call, right?
> >
> > No, why? Consider this:
> >
> > int write(...)
> > {
> > ...
> > mutex_lock(&instance->lock);
> > if (instance->disconnected) {
> > dev_dbg(instance->dev,"writing to disconnected device");
> > rv = -ENODEV;
> > } else {
> > res = usb_submit_urb(...);
> > rv = res < 0 ? -EIO : count;
> > }
> > mutex_unlock(&instance->lock);
> > return rv;
> > }
> >
> > void disconnect(...)
> > {
> > ...
> > mutex_lock(&instance->lock);
> > instance->disconnected = 1;
> > usb_kill_urb(...);
> > usb_kill_urb(...);
> > mutex_unlock(&instance->lock);
> > }
> >
> > This would be perfectly valid code without any references taken save
> > for the pesky dev_dbg()
>
> Whoever calls write() must possess a valid reference. Otherwise
> instance might already be deallocated when write() starts, causing an
> oops well before the call to dev_dbg().
He needs a valid reference to "instance", not to the device. In fact
he may do IO to the device only if he knows it hasn't been disconnected.
> Typically the driver would take a reference during open() and drop it
> during close().
You can do that but then you must not do IO prior to open() or after
close(). That is you must actually wait for IO to finish in close() and
cannot prefill your buffers before open().
Regards
Oliver
next prev parent reply other threads:[~2009-12-04 21:18 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20091204044337.GE14819@suse.de>
2009-12-04 16:06 ` Alan Stern
2009-12-04 16:16 ` Oliver Neukum
2009-12-04 16:50 ` Greg KH
2009-12-04 19:55 ` Oliver Neukum
2009-12-04 20:57 ` Alan Stern
2009-12-04 21:18 ` Oliver Neukum [this message]
2009-12-04 21:36 ` Alan Stern
2009-12-04 21:58 ` Oliver Neukum
2009-12-04 22:07 ` Alan Stern
2009-12-04 22:23 ` Dmitry Torokhov
2009-12-04 23:50 ` Alan Stern
2009-12-05 0:35 ` Greg KH
2009-12-05 2:37 ` Alan Stern
2009-12-05 0:33 ` Greg KH
2009-12-04 16:57 ` 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=200912042218.11410.oliver@neukum.org \
--to=oliver@neukum.org \
--cc=gregkh@suse.de \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=rickard.bellini@ericsson.com \
--cc=stable@kernel.org \
--cc=stern@rowland.harvard.edu \
--cc=torgny.johansson@ericsson.com \
/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
all inboxes | Powered by JetHome®