mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Thomas Pfaff <tpfaff@pcs.com>
To: linux-kernel@vger.kernel.org
Cc: Alan Cox <alan@lxorguk.ukuu.org.uk>
Subject: [PATCH] tty: Fix async io write notifications
Date: Mon, 24 Nov 2008 14:40:15 +0100 (CET)	[thread overview]
Message-ID: <Pine.LNX.4.64.0811241401280.8443@lxtpfaff.pcs.ditec.de> (raw)

From: Thomas Pfaff <tpfaff@pcs.com>

The N_TTY ldisc layer does not send SIGIO POLL_OUTs correctly when output is 
possible due to flawed handling of the TTY_DO_WRITE_WAKEUP bit. It will either 
send no SIGIOs at all or on every tty wakeup.

The fix is to set the bit when the tty driver write would block and test and 
clear it on write wakeup.

Signed-off-by: Thomas Pfaff <tpfaff@pcs.com>
Cc: Alan Cox <alan@lxorguk.ukuu.org.uk>
---
 drivers/char/n_tty.c |    8 +++++---
 1 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/char/n_tty.c b/drivers/char/n_tty.c
index efbfe96..4e0f4be 100644
--- a/drivers/char/n_tty.c
+++ b/drivers/char/n_tty.c
@@ -923,10 +923,8 @@ handle_newline:
 
 static void n_tty_write_wakeup(struct tty_struct *tty)
 {
-	if (tty->fasync) {
-		set_bit(TTY_DO_WRITE_WAKEUP, &tty->flags);
+	if (test_and_clear_bit(TTY_DO_WRITE_WAKEUP, &tty->flags))
 		kill_fasync(&tty->fasync, SIGIO, POLL_OUT);
-	}
 }
 
 /**
@@ -1556,6 +1554,8 @@ static ssize_t n_tty_write(struct tty_struct *tty, struct file *file,
 		}
 		if (!nr)
 			break;
+		if (tty->fasync)
+			set_bit(TTY_DO_WRITE_WAKEUP, &tty->flags);
 		if (file->f_flags & O_NONBLOCK) {
 			retval = -EAGAIN;
 			break;
@@ -1565,6 +1565,8 @@ static ssize_t n_tty_write(struct tty_struct *tty, struct file *file,
 break_out:
 	__set_current_state(TASK_RUNNING);
 	remove_wait_queue(&tty->write_wait, &wait);
+	if (tty->fasync && (b - buf) != nr)
+		set_bit(TTY_DO_WRITE_WAKEUP, &tty->flags);
 	return (b - buf) ? b - buf : retval;
 }
 

             reply	other threads:[~2008-11-24 13:40 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-11-24 13:40 Thomas Pfaff [this message]
2008-11-24 14:21 ` 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=Pine.LNX.4.64.0811241401280.8443@lxtpfaff.pcs.ditec.de \
    --to=tpfaff@pcs.com \
    --cc=alan@lxorguk.ukuu.org.uk \
    --cc=linux-kernel@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

all inboxes | Powered by JetHome®