All of lore.kernel.org
 help / color / mirror / Atom feed
From: Grant Edwards <grant.b.edwards@gmail.com>
To: linux-serial@vger.kernel.org
Subject: tty_reopen() returning -EIO because port is closing
Date: Fri, 18 Jan 2013 21:23:10 +0000 (UTC)	[thread overview]
Message-ID: <kdcefu$dbc$1@ger.gmane.org> (raw)

During testing of a tty driver that's just been updated to use the
tty_port_ helper functions, I'm seeing a test failure in user-space
when open() returns -EIO.

The failure occurs sporadically (maybe 1 failure per 100 opens) when
running a test that has multiple threads all opening and closing the
same serial port (more or less at random).

It's worth noting that my port activate and shutdown functions sleep.

Typically, they sleep for a few ms [this is the case during the tests
I've been running].  But, there are use cases where they could sleep
for hundreds of ms.

I've tracked the failure to tty_reopen() in tty_io.c [3.8-rc3]:

  1331	static int tty_reopen(struct tty_struct *tty)
  1332	{
  1333	        struct tty_driver *driver = tty->driver;
  1334	
  1335	        if (test_bit(TTY_CLOSING, &tty->flags) ||
  1336	                        test_bit(TTY_HUPPING, &tty->flags) ||
  1337	                        test_bit(TTY_LDISC_CHANGING, &tty->flags))
  1338	                return -EIO;

Line 1338 is returning -EIO because test_bit(TTY_CLOSING, &tty->flags)
is true.

Can this be caused by a bug in my driver?

If not, is it a bug in the tty layer?

Does Posix say than an open() may fail if it's called while another
process is calling close()?  IOW, is user-space code expected to retry
an open() call that returns EIO?  [I've never seen user-space code
that did that...]

-- 
Grant Edwards               grant.b.edwards        Yow! I'm having a RELIGIOUS
                                  at               EXPERIENCE ... and I don't
                              gmail.com            take any DRUGS


             reply	other threads:[~2013-01-18 21:23 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-01-18 21:23 Grant Edwards [this message]
2013-01-18 21:52 ` tty_reopen() returning -EIO because port is closing Alan Cox
2013-01-18 22:06   ` Grant Edwards
2013-01-20 16:52     ` Alan Cox

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='kdcefu$dbc$1@ger.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 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.