linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Nicolas Pitre <nico@cam.org>
To: Linus Torvalds <torvalds@transmeta.com>
Cc: Alan Cox <alan@lxorguk.ukuu.org.uk>, lkml <linux-kernel@vger.kernel.org>
Subject: Re: [patch] small tty irq race fix
Date: Mon, 3 Mar 2003 16:51:42 -0500 (EST)	[thread overview]
Message-ID: <Pine.LNX.4.44.0303031650230.31566-100000@xanadu.home> (raw)
In-Reply-To: <Pine.LNX.4.44.0303031338260.12285-100000@home.transmeta.com>

On Mon, 3 Mar 2003, Linus Torvalds wrote:

> 
> On Mon, 3 Mar 2003, Nicolas Pitre wrote:
> > 
> > What about this one?  It just happens that tty->read_lock is actually used
> > deeper in the same call instance (in n_tty.c) so this looks to be the best
> > lock to use.
> 
> Looks ok. I would suggest moving the "spin_lock_irqsave()" to outside the 
> 'if'-statement, though, since that should make the code a lot more 
> readable, and if the lock is supposed to protect tty->flip.buf_num, then 
> let's do it right and protect the read as well, no?

Oh sure.

--- linux-2.5.63/drivers/char/tty_io.c.orig	Mon Feb 24 14:05:34 2003
+++ linux-2.5.63/drivers/char/tty_io.c	Mon Mar  3 16:49:44 2003
@@ -1944,27 +1944,25 @@
 		schedule_delayed_work(&tty->flip.work, 1);
 		return;
 	}
+
+	spin_lock_irqsave(&tty->read_lock, flags);
 	if (tty->flip.buf_num) {
 		cp = tty->flip.char_buf + TTY_FLIPBUF_SIZE;
 		fp = tty->flip.flag_buf + TTY_FLIPBUF_SIZE;
 		tty->flip.buf_num = 0;
-
-		local_irq_save(flags); // FIXME: is this safe?
 		tty->flip.char_buf_ptr = tty->flip.char_buf;
 		tty->flip.flag_buf_ptr = tty->flip.flag_buf;
 	} else {
 		cp = tty->flip.char_buf;
 		fp = tty->flip.flag_buf;
 		tty->flip.buf_num = 1;
-
-		local_irq_save(flags); // FIXME: is this safe?
 		tty->flip.char_buf_ptr = tty->flip.char_buf + TTY_FLIPBUF_SIZE;
 		tty->flip.flag_buf_ptr = tty->flip.flag_buf + TTY_FLIPBUF_SIZE;
 	}
 	count = tty->flip.count;
 	tty->flip.count = 0;
-	local_irq_restore(flags); // FIXME: is this safe?
-	
+	spin_unlock_irqrestore(&tty->read_lock, flags);
+
 	tty->ldisc.receive_buf(tty, cp, fp, count);
 }
 


Nicolas


      reply	other threads:[~2003-03-03 21:41 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-03-03 18:09 [patch] small tty irq race fix Nicolas Pitre
2003-03-03 20:06 ` Alan Cox
2003-03-03 19:15   ` Nicolas Pitre
2003-03-03 21:20   ` Nicolas Pitre
2003-03-03 21:39     ` Linus Torvalds
2003-03-03 21:51       ` Nicolas Pitre [this message]

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.44.0303031650230.31566-100000@xanadu.home \
    --to=nico@cam.org \
    --cc=alan@lxorguk.ukuu.org.uk \
    --cc=linux-kernel@vger.kernel.org \
    --cc=torvalds@transmeta.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;
as well as URLs for NNTP newsgroup(s).