Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 29 Jun 2012 12:08:27 +0000 (UTC)
From:      Peter Holm <pho@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-9@freebsd.org
Subject:   svn commit: r237775 - stable/9/sys/kern
Message-ID:  <201206291208.q5TC8Rac044638@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: pho
Date: Fri Jun 29 12:08:26 2012
New Revision: 237775
URL: http://svn.freebsd.org/changeset/base/237775

Log:
  MFC: r237219
  
  In tty_makedev() the following construction:
  
  dev = make_dev_cred();
  dev->si_drv1 = tp;
  
  leaves a small window where the newly created device may be opened
  and si_drv1 is NULL.
  
  As this is a vary rare situation, using a lock to close the window
  seems overkill. Instead just wait for the assignment of si_drv1.

Modified:
  stable/9/sys/kern/tty.c
Directory Properties:
  stable/9/sys/   (props changed)

Modified: stable/9/sys/kern/tty.c
==============================================================================
--- stable/9/sys/kern/tty.c	Fri Jun 29 12:05:19 2012	(r237774)
+++ stable/9/sys/kern/tty.c	Fri Jun 29 12:08:26 2012	(r237775)
@@ -219,9 +219,15 @@ ttydev_leave(struct tty *tp)
 static int
 ttydev_open(struct cdev *dev, int oflags, int devtype, struct thread *td)
 {
-	struct tty *tp = dev->si_drv1;
+	struct tty *tp;
 	int error = 0;
 
+	while ((tp = dev->si_drv1) == NULL) {
+		error = tsleep(&dev->si_drv1, PCATCH, "ttdrv1", 1);
+		if (error != EWOULDBLOCK)
+			return (error);
+	}
+
 	tty_lock(tp);
 	if (tty_gone(tp)) {
 		/* Device is already gone. */
@@ -738,9 +744,14 @@ static struct cdevsw ttydev_cdevsw = {
 static int
 ttyil_open(struct cdev *dev, int oflags, int devtype, struct thread *td)
 {
-	struct tty *tp = dev->si_drv1;
+	struct tty *tp;
 	int error = 0;
 
+	while ((tp = dev->si_drv1) == NULL) {
+		error = tsleep(&dev->si_drv1, PCATCH, "ttdrv1", 1);
+		if (error != EWOULDBLOCK)
+			return (error);
+	}
 	tty_lock(tp);
 	if (tty_gone(tp))
 		error = ENODEV;
@@ -1203,6 +1214,7 @@ tty_makedev(struct tty *tp, struct ucred
 	dev = make_dev_cred(&ttydev_cdevsw, 0, cred,
 	    uid, gid, mode, "%s%s", prefix, name);
 	dev->si_drv1 = tp;
+	wakeup(&dev->si_drv1);
 	tp->t_dev = dev;
 
 	/* Slave call-in devices. */
@@ -1211,12 +1223,14 @@ tty_makedev(struct tty *tp, struct ucred
 		    uid, gid, mode, "%s%s.init", prefix, name);
 		dev_depends(tp->t_dev, dev);
 		dev->si_drv1 = tp;
+		wakeup(&dev->si_drv1);
 		dev->si_drv2 = &tp->t_termios_init_in;
 
 		dev = make_dev_cred(&ttyil_cdevsw, TTYUNIT_LOCK, cred,
 		    uid, gid, mode, "%s%s.lock", prefix, name);
 		dev_depends(tp->t_dev, dev);
 		dev->si_drv1 = tp;
+		wakeup(&dev->si_drv1);
 		dev->si_drv2 = &tp->t_termios_lock_in;
 	}
 
@@ -1226,6 +1240,7 @@ tty_makedev(struct tty *tp, struct ucred
 		    UID_UUCP, GID_DIALER, 0660, "cua%s", name);
 		dev_depends(tp->t_dev, dev);
 		dev->si_drv1 = tp;
+		wakeup(&dev->si_drv1);
 
 		/* Slave call-out devices. */
 		if (tp->t_flags & TF_INITLOCK) {
@@ -1234,6 +1249,7 @@ tty_makedev(struct tty *tp, struct ucred
 			    UID_UUCP, GID_DIALER, 0660, "cua%s.init", name);
 			dev_depends(tp->t_dev, dev);
 			dev->si_drv1 = tp;
+			wakeup(&dev->si_drv1);
 			dev->si_drv2 = &tp->t_termios_init_out;
 
 			dev = make_dev_cred(&ttyil_cdevsw,
@@ -1241,6 +1257,7 @@ tty_makedev(struct tty *tp, struct ucred
 			    UID_UUCP, GID_DIALER, 0660, "cua%s.lock", name);
 			dev_depends(tp->t_dev, dev);
 			dev->si_drv1 = tp;
+			wakeup(&dev->si_drv1);
 			dev->si_drv2 = &tp->t_termios_lock_out;
 		}
 	}



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201206291208.q5TC8Rac044638>