From owner-svn-src-head@freebsd.org Fri May 27 17:00:16 2016 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id D3A34B4BC8E; Fri, 27 May 2016 17:00:16 +0000 (UTC) (envelope-from mjg@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 7E6C91E18; Fri, 27 May 2016 17:00:16 +0000 (UTC) (envelope-from mjg@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u4RH0FLY059504; Fri, 27 May 2016 17:00:15 GMT (envelope-from mjg@FreeBSD.org) Received: (from mjg@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u4RH0FEL059503; Fri, 27 May 2016 17:00:15 GMT (envelope-from mjg@FreeBSD.org) Message-Id: <201605271700.u4RH0FEL059503@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: mjg set sender to mjg@FreeBSD.org using -f From: Mateusz Guzik Date: Fri, 27 May 2016 17:00:15 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r300852 - head/sys/kern X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 27 May 2016 17:00:16 -0000 Author: mjg Date: Fri May 27 17:00:15 2016 New Revision: 300852 URL: https://svnweb.freebsd.org/changeset/base/300852 Log: fd: provide a common exit point for unlock in kern_dup While here assert dropped filedesc lock on return from closefp. Modified: head/sys/kern/kern_descrip.c Modified: head/sys/kern/kern_descrip.c ============================================================================== --- head/sys/kern/kern_descrip.c Fri May 27 15:03:38 2016 (r300851) +++ head/sys/kern/kern_descrip.c Fri May 27 17:00:15 2016 (r300852) @@ -833,17 +833,16 @@ kern_dup(struct thread *td, u_int mode, 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, 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, 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, #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); } /*