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
This commit is contained in:
Conrad Meyer 2018-10-26 20:07:46 +00:00
parent 0fb8835bcf
commit 2384981b61
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=339786

View File

@ -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 nfds,
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 nfds,
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 @@ kern_poll(struct thread *td, struct pollfd *fds, u_int nfds,
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);
}