From owner-svn-src-head@freebsd.org Wed Sep 23 12:45:09 2015 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 2B394A02DFA; Wed, 23 Sep 2015 12:45:09 +0000 (UTC) (envelope-from mjg@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2001:1900:2254:2068::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 1BCD51B0B; Wed, 23 Sep 2015 12:45:09 +0000 (UTC) (envelope-from mjg@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.70]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id t8NCj8Y4029755; Wed, 23 Sep 2015 12:45:08 GMT (envelope-from mjg@FreeBSD.org) Received: (from mjg@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id t8NCj8RL029754; Wed, 23 Sep 2015 12:45:08 GMT (envelope-from mjg@FreeBSD.org) Message-Id: <201509231245.t8NCj8RL029754@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: mjg set sender to mjg@FreeBSD.org using -f From: Mateusz Guzik Date: Wed, 23 Sep 2015 12:45:08 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r288145 - 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.20 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: Wed, 23 Sep 2015 12:45:09 -0000 Author: mjg Date: Wed Sep 23 12:45:08 2015 New Revision: 288145 URL: https://svnweb.freebsd.org/changeset/base/288145 Log: kqueue: simplify kern_kqueue by not refing/unrefing creds too early No functional changes. Modified: head/sys/kern/kern_event.c Modified: head/sys/kern/kern_event.c ============================================================================== --- head/sys/kern/kern_event.c Wed Sep 23 07:44:07 2015 (r288144) +++ head/sys/kern/kern_event.c Wed Sep 23 12:45:08 2015 (r288145) @@ -759,28 +759,25 @@ kern_kqueue(struct thread *td, int flags struct filedesc *fdp; struct kqueue *kq; struct file *fp; - struct proc *p; struct ucred *cred; int fd, error; - p = td->td_proc; + fdp = td->td_proc->p_fd; cred = td->td_ucred; - crhold(cred); - if (!chgkqcnt(cred->cr_ruidinfo, 1, lim_cur(td, RLIMIT_KQUEUES))) { - crfree(cred); + if (!chgkqcnt(cred->cr_ruidinfo, 1, lim_cur(td, RLIMIT_KQUEUES))) return (ENOMEM); - } - fdp = p->p_fd; error = falloc_caps(td, &fp, &fd, flags, fcaps); - if (error) - goto done2; + if (error != 0) { + chgkqcnt(cred->cr_ruidinfo, -1, 0); + return (error); + } /* An extra reference on `fp' has been held for us by falloc(). */ kq = malloc(sizeof *kq, M_KQUEUE, M_WAITOK | M_ZERO); kqueue_init(kq); kq->kq_fdp = fdp; - kq->kq_cred = cred; + kq->kq_cred = crhold(cred); FILEDESC_XLOCK(fdp); TAILQ_INSERT_HEAD(&fdp->fd_kqlist, kq, kq_list); @@ -790,12 +787,7 @@ kern_kqueue(struct thread *td, int flags fdrop(fp, td); td->td_retval[0] = fd; -done2: - if (error != 0) { - chgkqcnt(cred->cr_ruidinfo, -1, 0); - crfree(cred); - } - return (error); + return (0); } #ifndef _SYS_SYSPROTO_H_