diff options
author | Claudio Jeker <claudio@cvs.openbsd.org> | 2021-02-08 09:18:31 +0000 |
---|---|---|
committer | Claudio Jeker <claudio@cvs.openbsd.org> | 2021-02-08 09:18:31 +0000 |
commit | b923743397e30d5404402b001fef00b7da7dc59e (patch) | |
tree | 97c7593282de1640b69a7e96b6332198432717c0 /sys/kern | |
parent | 02aa9d2d2ffaf6fb967cb5cff61eb52d18bf3848 (diff) |
Do not hold onto the fdplock longer then needed. Release the lock after
the initial falloc() calls and then regrab it for the fdinsert() or
fdremove() calls respectiviely. Also move closef() outside of the lock.
This replaces the previously reverted lock order change that was reverted.
OK mvs@ visa@
Diffstat (limited to 'sys/kern')
-rw-r--r-- | sys/kern/tty_pty.c | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/sys/kern/tty_pty.c b/sys/kern/tty_pty.c index 4c97ba84543..660a2e86a9b 100644 --- a/sys/kern/tty_pty.c +++ b/sys/kern/tty_pty.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tty_pty.c,v 1.107 2021/02/04 13:32:33 claudio Exp $ */ +/* $OpenBSD: tty_pty.c,v 1.108 2021/02/08 09:18:30 claudio Exp $ */ /* $NetBSD: tty_pty.c,v 1.33.4.1 1996/06/02 09:08:11 mrg Exp $ */ /* @@ -1088,12 +1088,12 @@ ptmclose(dev_t dev, int flag, int mode, struct proc *p) int ptmioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p) { - dev_t newdev, error; + dev_t newdev; struct pt_softc * pti; struct nameidata cnd, snd; struct filedesc *fdp = p->p_fd; struct file *cfp = NULL, *sfp = NULL; - int cindx, sindx; + int cindx, sindx, error; uid_t uid; gid_t gid; struct vattr vattr; @@ -1110,10 +1110,11 @@ ptmioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p) } if ((error = falloc(p, &sfp, &sindx)) != 0) { fdremove(fdp, cindx); - closef(cfp, p); fdpunlock(fdp); + closef(cfp, p); break; } + fdpunlock(fdp); retry: /* Find and open a free master pty. */ @@ -1203,6 +1204,7 @@ retry: memcpy(ptm->sn, pti->pty_sn, sizeof(pti->pty_sn)); /* insert files now that we've passed all errors */ + fdplock(fdp); fdinsert(fdp, cindx, 0, cfp); fdinsert(fdp, sindx, 0, sfp); fdpunlock(fdp); @@ -1215,10 +1217,11 @@ retry: } return (error); bad: + fdplock(fdp); fdremove(fdp, cindx); - closef(cfp, p); fdremove(fdp, sindx); - closef(sfp, p); fdpunlock(fdp); + closef(cfp, p); + closef(sfp, p); return (error); } |