From: Grant Edwards <grant.b.edwards@gmail.com>
To: linux-serial@vger.kernel.org
Subject: Re: close() handler of tty driver called for port that's not open?
Date: Wed, 14 Sep 2011 19:52:59 +0000 (UTC) [thread overview]
Message-ID: <j4r0mr$veq$1@dough.gmane.org> (raw)
In-Reply-To: 20110914203353.08c715af@lxorguk.ukuu.org.uk
On 2011-09-14, Alan Cox <alan@lxorguk.ukuu.org.uk> wrote:
> Grant Edwards <grant.b.edwards@gmail.com> wrote:
>
>> Why does the tty layer call my tty driver's close() handler on a port
>> that's not open?
>
> Because a lot of the tty drivers it makes sense to structure the
> cleanup this way.
>
>> Why does the tty layer try to close a device that isn't open?
>
> Because it was originally designed that way
Interesting. I only noticed it recently, but I think that may be
because of other changes made to the kernel.
>> Does the tty consider a device to be open even if the open() handler
>> returned an error?
>
> Define "open". The answer depends upon what you mean by "open"
In my mind, a port was only open after my open() handler returns
success. I guess that's wrong, and I should increment my use counter
unconditionally each time my open() handler is called.
>> The problem is that my driver keeps a usage count on the port so it
>> can clean up some internal stuff when the last user closes a port.
>
> Use the tty_port helpers and it'll do that for you including the
> locking, blocking, POSIX open blocking/waiting semantics, error
> handling, callbacks and hangup. Trying to open code this stuff is a
> world of pain and the locking rules are now much more your problem as
> we strip out the remains of the big kernel lock.
Thanks for the suggestion. I've looked at those, but not all my
customers are running kernels recent enough to have those helpers. I
suppose I could look into writing compatibility versions compatible
with the range of kernels I have to support.
>> Does the tty layer guarantee that the number of close() calls will
>> match the number of open() calls regardless of whether the open()
>> calls succeed or not?
>>
>> If so, has that always been the policy, or is calling close() on
>> non-open device a new feature?
>
> The tty layer has always worked that way. It's I think unique in that
> behaviour in the kernel.
It seems that recent improvements to the kenel's pre-emptibility are
showing up all sorts of decade-old holes in this driver. :/
> If you use the tty_port_open/hangup/close boilerplate then you can
> provide shutdown and activate port methods. The guarantee they
> provide is that they will be called in matching pairs, they will be
> called in the correct places, they will not be called in parallel
> with one another and they will properly handle hangup() events -
> where you shutdown on the hangup but the close occurs afterwards.
The problem is how to make a driver written that way work for somebody
running a 2.4 kernel (or even a not-very-recent 2.6 kernel). Yes, I
have a few customers running 2.4 kernels, and lots of customers
running older 2.6 kernels. I _might_ be able to convince management
it's time to drop support for 2.4, but there's no way I can abandon
customers using 2.6 kernels.
> In an ideal world eventually everything will be using the tty port
> helpers and then we can make that the underlying (sane) tty interface
> and clean up the rest.
--
Grant Edwards grant.b.edwards Yow! ... I have read the
at INSTRUCTIONS ...
gmail.com
next prev parent reply other threads:[~2011-09-14 19:53 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-09-14 16:21 close() handler of tty driver called for port that's not open? Grant Edwards
2011-09-14 19:33 ` Alan Cox
2011-09-14 19:52 ` Grant Edwards [this message]
2011-09-14 20:05 ` Alan Cox
2011-09-14 20:13 ` Grant Edwards
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='j4r0mr$veq$1@dough.gmane.org' \
--to=grant.b.edwards@gmail.com \
--cc=linux-serial@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;
as well as URLs for NNTP newsgroup(s).