diff options
author | mjg <mjg@FreeBSD.org> | 2014-06-22 01:31:55 +0000 |
---|---|---|
committer | mjg <mjg@FreeBSD.org> | 2014-06-22 01:31:55 +0000 |
commit | d74326bc91b75e4a8f54bcc1fdb0a83ab223e560 (patch) | |
tree | da5e63a89bfc99a89e509c6cae0e1bd9a50d4de5 | |
parent | 38cd838637eab022e13231e78d0727fb8ac4da12 (diff) | |
download | FreeBSD-src-d74326bc91b75e4a8f54bcc1fdb0a83ab223e560.zip FreeBSD-src-d74326bc91b75e4a8f54bcc1fdb0a83ab223e560.tar.gz |
fd: replace fd_nfiles with fd_lastfile where appropriate
fd_lastfile is guaranteed to be the biggest open fd, so when the intent
is to iterate over active fds or lookup one, there is no point in looking
beyond that limit.
Few places are left unpatched for now.
MFC after: 1 week
-rw-r--r-- | sys/kern/kern_descrip.c | 12 | ||||
-rw-r--r-- | sys/kern/sys_generic.c | 2 | ||||
-rw-r--r-- | sys/kern/vfs_syscalls.c | 2 | ||||
-rw-r--r-- | sys/sys/filedesc.h | 2 |
4 files changed, 9 insertions, 9 deletions
diff --git a/sys/kern/kern_descrip.c b/sys/kern/kern_descrip.c index 9c0d7c0..267b317 100644 --- a/sys/kern/kern_descrip.c +++ b/sys/kern/kern_descrip.c @@ -1234,7 +1234,7 @@ sys_closefrom(struct thread *td, struct closefrom_args *uap) if (uap->lowfd < 0) uap->lowfd = 0; FILEDESC_SLOCK(fdp); - for (fd = uap->lowfd; fd < fdp->fd_nfiles; fd++) { + for (fd = uap->lowfd; fd <= fdp->fd_lastfile; fd++) { if (fdp->fd_ofiles[fd].fde_file != NULL) { FILEDESC_SUNLOCK(fdp); (void)kern_close(td, fd); @@ -2916,7 +2916,7 @@ sysctl_kern_file(SYSCTL_HANDLER_ARGS) if (fdp == NULL) continue; FILEDESC_SLOCK(fdp); - for (n = 0; fdp->fd_refcnt > 0 && n < fdp->fd_nfiles; ++n) { + for (n = 0; fdp->fd_refcnt > 0 && n <= fdp->fd_lastfile; ++n) { if ((fp = fdp->fd_ofiles[n].fde_file) == NULL) continue; xf.xf_fd = n; @@ -3026,7 +3026,7 @@ sysctl_kern_proc_ofiledesc(SYSCTL_HANDLER_ARGS) if (fdp->fd_jdir != NULL) export_vnode_for_osysctl(fdp->fd_jdir, KF_FD_TYPE_JAIL, kif, fdp, req); - for (i = 0; fdp->fd_refcnt > 0 && i < fdp->fd_nfiles; i++) { + for (i = 0; fdp->fd_refcnt > 0 && i <= fdp->fd_lastfile; i++) { if ((fp = fdp->fd_ofiles[i].fde_file) == NULL) continue; bzero(kif, sizeof(*kif)); @@ -3395,7 +3395,7 @@ kern_proc_filedesc_out(struct proc *p, struct sbuf *sb, ssize_t maxlen) export_fd_to_sb(data, KF_TYPE_VNODE, KF_FD_TYPE_JAIL, FREAD, -1, -1, NULL, efbuf); } - for (i = 0; fdp->fd_refcnt > 0 && i < fdp->fd_nfiles; i++) { + for (i = 0; fdp->fd_refcnt > 0 && i <= fdp->fd_lastfile; i++) { if ((fp = fdp->fd_ofiles[i].fde_file) == NULL) continue; data = NULL; @@ -3766,7 +3766,7 @@ file_to_first_proc(struct file *fp) fdp = p->p_fd; if (fdp == NULL) continue; - for (n = 0; n < fdp->fd_nfiles; n++) { + for (n = 0; n <= fdp->fd_lastfile; n++) { if (fp == fdp->fd_ofiles[n].fde_file) return (p); } @@ -3816,7 +3816,7 @@ DB_SHOW_COMMAND(files, db_show_files) continue; if ((fdp = p->p_fd) == NULL) continue; - for (n = 0; n < fdp->fd_nfiles; ++n) { + for (n = 0; n <= fdp->fd_lastfile; ++n) { if ((fp = fdp->fd_ofiles[n].fde_file) == NULL) continue; db_print_file(fp, header); diff --git a/sys/kern/sys_generic.c b/sys/kern/sys_generic.c index 6cc4f13..50bc91d 100644 --- a/sys/kern/sys_generic.c +++ b/sys/kern/sys_generic.c @@ -1458,7 +1458,7 @@ pollscan(td, fds, nfd) FILEDESC_SLOCK(fdp); for (i = 0; i < nfd; i++, fds++) { - if (fds->fd >= fdp->fd_nfiles) { + if (fds->fd > fdp->fd_lastfile) { fds->revents = POLLNVAL; n++; } else if (fds->fd < 0) { diff --git a/sys/kern/vfs_syscalls.c b/sys/kern/vfs_syscalls.c index 8481fb4..7aa457e 100644 --- a/sys/kern/vfs_syscalls.c +++ b/sys/kern/vfs_syscalls.c @@ -828,7 +828,7 @@ chroot_refuse_vdir_fds(fdp) FILEDESC_LOCK_ASSERT(fdp); - for (fd = 0; fd < fdp->fd_nfiles ; fd++) { + for (fd = 0; fd <= fdp->fd_lastfile; fd++) { fp = fget_locked(fdp, fd); if (fp == NULL) continue; diff --git a/sys/sys/filedesc.h b/sys/sys/filedesc.h index 516ef1b..972cfc9 100644 --- a/sys/sys/filedesc.h +++ b/sys/sys/filedesc.h @@ -175,7 +175,7 @@ fget_locked(struct filedesc *fdp, int fd) FILEDESC_LOCK_ASSERT(fdp); - if (fd < 0 || fd >= fdp->fd_nfiles) + if (fd < 0 || fd > fdp->fd_lastfile) return (NULL); return (fdp->fd_ofiles[fd].fde_file); |