Module Name:    src
Committed By:   mlelstv
Date:           Sun Sep 30 11:49:44 UTC 2012

Modified Files:
        src/sys/kern: tty.c

Log Message:
Provide consistent locking around getc() in ttread(). This is necessary
to prevent crashes in MPSAFE tty drivers like ucom.


To generate a diff of this commit:
cvs rdiff -u -r1.253 -r1.254 src/sys/kern/tty.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/tty.c
diff -u src/sys/kern/tty.c:1.253 src/sys/kern/tty.c:1.254
--- src/sys/kern/tty.c:1.253	Fri Aug 17 16:21:19 2012
+++ src/sys/kern/tty.c	Sun Sep 30 11:49:44 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: tty.c,v 1.253 2012/08/17 16:21:19 christos Exp $	*/
+/*	$NetBSD: tty.c,v 1.254 2012/09/30 11:49:44 mlelstv Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -63,7 +63,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: tty.c,v 1.253 2012/08/17 16:21:19 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tty.c,v 1.254 2012/09/30 11:49:44 mlelstv Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -1928,7 +1928,6 @@ ttread(struct tty *tp, struct uio *uio, 
 		goto loop;
 	}
  read:
-	mutex_spin_exit(&tty_lock);
 
 	/*
 	 * Input present, check for input mapping and processing.
@@ -1940,16 +1939,14 @@ ttread(struct tty *tp, struct uio *uio, 
 		 */
 		if (CCEQ(cc[VDSUSP], c) &&
 		    ISSET(lflag, IEXTEN|ISIG) == (IEXTEN|ISIG)) {
-			mutex_spin_enter(&tty_lock);
 			ttysig(tp, TTYSIG_PG1, SIGTSTP);
 			if (first) {
 				error = ttypause(tp, hz);
-				mutex_spin_exit(&tty_lock);
 				if (error)
 					break;
-				goto loop;
-			} else
 				mutex_spin_exit(&tty_lock);
+				goto loop;
+			}
 			break;
 		}
 		/*
@@ -1973,11 +1970,11 @@ ttread(struct tty *tp, struct uio *uio, 
 			break;
 		first = 0;
 	}
+
 	/*
 	 * Look to unblock output now that (presumably)
 	 * the input queue has gone down.
 	 */
-	mutex_spin_enter(&tty_lock);
 	if (ISSET(tp->t_state, TS_TBLOCK) && tp->t_rawq.c_cc < TTYHOG / 5) {
 		if (ISSET(tp->t_iflag, IXOFF) &&
 		    cc[VSTART] != _POSIX_VDISABLE &&

Reply via email to