From owner-svn-src-head@freebsd.org Fri Oct 26 20:07:47 2018 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 8967510874C3; Fri, 26 Oct 2018 20:07:47 +0000 (UTC) (envelope-from cem@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 3B34985D8F; Fri, 26 Oct 2018 20:07:47 +0000 (UTC) (envelope-from cem@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 mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 0FFB4259E2; Fri, 26 Oct 2018 20:07:47 +0000 (UTC) (envelope-from cem@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w9QK7kV4060286; Fri, 26 Oct 2018 20:07:46 GMT (envelope-from cem@FreeBSD.org) Received: (from cem@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w9QK7kRB060285; Fri, 26 Oct 2018 20:07:46 GMT (envelope-from cem@FreeBSD.org) Message-Id: <201810262007.w9QK7kRB060285@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: cem set sender to cem@FreeBSD.org using -f From: Conrad Meyer Date: Fri, 26 Oct 2018 20:07:46 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r339786 - head/sys/kern X-SVN-Group: head X-SVN-Commit-Author: cem X-SVN-Commit-Paths: head/sys/kern X-SVN-Commit-Revision: 339786 X-SVN-Commit-Repository: base 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.29 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, 26 Oct 2018 20:07:47 -0000 Author: cem Date: Fri Oct 26 20:07:46 2018 New Revision: 339786 URL: https://svnweb.freebsd.org/changeset/base/339786 Log: poll: Unify userspace pollfd pointer name Some of the poll code used 'fds' and some used 'ufds' to refer to the uap->fds userspace pointer that was passed around to subroutines. Some of the poll code used 'fds' to refer to the kernel memory pollfd arrays, which seemed unnecessarily confusing. Unify on 'ufds' to refer to the userspace pollfd array. Additionally, 'bits' is not an accurate description of the kernel pollfd array in kern_poll, so rename that to 'kfds'. Finally, clean up some logic with mallocarray() and nitems(). No functional change. Reviewed by: markj Differential Revision: https://reviews.freebsd.org/D17670 Modified: head/sys/kern/sys_generic.c Modified: head/sys/kern/sys_generic.c ============================================================================== --- head/sys/kern/sys_generic.c Fri Oct 26 20:03:59 2018 (r339785) +++ head/sys/kern/sys_generic.c Fri Oct 26 20:07:46 2018 (r339786) @@ -1304,16 +1304,15 @@ sys_poll(struct thread *td, struct poll_args *uap) } int -kern_poll(struct thread *td, struct pollfd *fds, u_int nfds, +kern_poll(struct thread *td, struct pollfd *ufds, u_int nfds, struct timespec *tsp, sigset_t *uset) { - struct pollfd *bits; - struct pollfd smallbits[32]; + struct pollfd *kfds; + struct pollfd stackfds[32]; sbintime_t sbt, precision, tmp; time_t over; struct timespec ts; int error; - size_t ni; precision = 0; if (tsp != NULL) { @@ -1342,12 +1341,11 @@ kern_poll(struct thread *td, struct pollfd *fds, u_int if (nfds > maxfilesperproc && nfds > FD_SETSIZE) return (EINVAL); - ni = nfds * sizeof(struct pollfd); - if (ni > sizeof(smallbits)) - bits = malloc(ni, M_TEMP, M_WAITOK); + if (nfds > nitems(stackfds)) + kfds = mallocarray(nfds, sizeof(*kfds), M_TEMP, M_WAITOK); else - bits = smallbits; - error = copyin(fds, bits, ni); + kfds = stackfds; + error = copyin(ufds, kfds, nfds * sizeof(*kfds)); if (error) goto done; @@ -1370,7 +1368,7 @@ kern_poll(struct thread *td, struct pollfd *fds, u_int seltdinit(td); /* Iterate until the timeout expires or descriptors become ready. */ for (;;) { - error = pollscan(td, bits, nfds); + error = pollscan(td, kfds, nfds); if (error || td->td_retval[0] != 0) break; error = seltdwait(td, sbt, precision); @@ -1389,13 +1387,13 @@ done: if (error == EWOULDBLOCK) error = 0; if (error == 0) { - error = pollout(td, bits, fds, nfds); + error = pollout(td, kfds, ufds, nfds); if (error) goto out; } out: - if (ni > sizeof(smallbits)) - free(bits, M_TEMP); + if (nfds > nitems(stackfds)) + free(kfds, M_TEMP); return (error); }