Date: Fri, 26 Oct 2018 20:07:46 +0000 (UTC) From: Conrad Meyer <cem@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r339786 - head/sys/kern Message-ID: <201810262007.w9QK7kRB060285@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
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); }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201810262007.w9QK7kRB060285>