diff options
author | pho <pho@FreeBSD.org> | 2012-06-18 07:34:38 +0000 |
---|---|---|
committer | pho <pho@FreeBSD.org> | 2012-06-18 07:34:38 +0000 |
commit | 85a3f61dca1bdf79e3879af425c06e9ee30829ad (patch) | |
tree | 27c833177cccfff2a3e52b545b9cec7acc615af7 /sys/kern | |
parent | 5958fc908c1cd2b73e214062694a231a7d8c6f53 (diff) | |
download | FreeBSD-src-85a3f61dca1bdf79e3879af425c06e9ee30829ad.zip FreeBSD-src-85a3f61dca1bdf79e3879af425c06e9ee30829ad.tar.gz |
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.
Suggested by: kib
MFC after: 1 week
Diffstat (limited to 'sys/kern')
-rw-r--r-- | sys/kern/tty.c | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/sys/kern/tty.c b/sys/kern/tty.c index 7ddcb0b..e9c0fb6 100644 --- a/sys/kern/tty.c +++ b/sys/kern/tty.c @@ -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 *cred, const char *fmt, ...) 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 *cred, const char *fmt, ...) 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 *cred, const char *fmt, ...) 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 *cred, const char *fmt, ...) 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 *cred, const char *fmt, ...) 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; } } |