diff options
author | mjg <mjg@FreeBSD.org> | 2016-05-27 17:00:15 +0000 |
---|---|---|
committer | mjg <mjg@FreeBSD.org> | 2016-05-27 17:00:15 +0000 |
commit | 3cca53e0a8711f87ce3032fadabbbd3241514ca2 (patch) | |
tree | 20bc1ca7addcdd5c1dc6af55b8c101f00222a1e8 /sys/kern | |
parent | 4a70fa3997a8f39ac1e4c7fef386c50b23ba22c5 (diff) | |
download | FreeBSD-src-3cca53e0a8711f87ce3032fadabbbd3241514ca2.zip FreeBSD-src-3cca53e0a8711f87ce3032fadabbbd3241514ca2.tar.gz |
fd: provide a common exit point for unlock in kern_dup
While here assert dropped filedesc lock on return from closefp.
Diffstat (limited to 'sys/kern')
-rw-r--r-- | sys/kern/kern_descrip.c | 34 |
1 files changed, 16 insertions, 18 deletions
diff --git a/sys/kern/kern_descrip.c b/sys/kern/kern_descrip.c index a0b07d1..7f0ef8d 100644 --- a/sys/kern/kern_descrip.c +++ b/sys/kern/kern_descrip.c @@ -833,17 +833,16 @@ kern_dup(struct thread *td, u_int mode, int flags, int old, int new) if (new >= maxfd) return (mode == FDDUP_FCNTL ? EINVAL : EBADF); + error = EBADF; FILEDESC_XLOCK(fdp); - if (fget_locked(fdp, old) == NULL) { - FILEDESC_XUNLOCK(fdp); - return (EBADF); - } + if (fget_locked(fdp, old) == NULL) + goto unlock; if ((mode == FDDUP_FIXED || mode == FDDUP_MUSTREPLACE) && old == new) { td->td_retval[0] = new; if (flags & FDDUP_FLAG_CLOEXEC) fdp->fd_ofiles[new].fde_flags |= UF_EXCLOSE; - FILEDESC_XUNLOCK(fdp); - return (0); + error = 0; + goto unlock; } /* @@ -854,17 +853,13 @@ kern_dup(struct thread *td, u_int mode, int flags, int old, int new) switch (mode) { case FDDUP_NORMAL: case FDDUP_FCNTL: - if ((error = fdalloc(td, new, &new)) != 0) { - FILEDESC_XUNLOCK(fdp); - return (error); - } + if ((error = fdalloc(td, new, &new)) != 0) + goto unlock; break; case FDDUP_MUSTREPLACE: /* Target file descriptor must exist. */ - if (fget_locked(fdp, new) == NULL) { - FILEDESC_XUNLOCK(fdp); - return (EBADF); - } + if (fget_locked(fdp, new) == NULL) + goto unlock; break; case FDDUP_FIXED: if (new >= fdp->fd_nfiles) { @@ -882,8 +877,8 @@ kern_dup(struct thread *td, u_int mode, int flags, int old, int new) error = racct_set(p, RACCT_NOFILE, new + 1); PROC_UNLOCK(p); if (error != 0) { - FILEDESC_XUNLOCK(fdp); - return (EMFILE); + error = EMFILE; + goto unlock; } } #endif @@ -921,14 +916,17 @@ kern_dup(struct thread *td, u_int mode, int flags, int old, int new) #endif td->td_retval[0] = new; + error = 0; + if (delfp != NULL) { (void) closefp(fdp, new, delfp, td, 1); - /* closefp() drops the FILEDESC lock for us. */ + FILEDESC_UNLOCK_ASSERT(fdp); } else { +unlock: FILEDESC_XUNLOCK(fdp); } - return (0); + return (error); } /* |