diff options
author | mjg <mjg@FreeBSD.org> | 2014-07-06 22:54:17 +0000 |
---|---|---|
committer | mjg <mjg@FreeBSD.org> | 2014-07-06 22:54:17 +0000 |
commit | 4ec4a6585547ae29000dc768cf108796f523d42a (patch) | |
tree | e46ad6df7605189eef26054537d618b971177e94 /sys/kern/kern_descrip.c | |
parent | bfa18e46636c505178365dff658104704cd4e1c8 (diff) | |
download | FreeBSD-src-4ec4a6585547ae29000dc768cf108796f523d42a.zip FreeBSD-src-4ec4a6585547ae29000dc768cf108796f523d42a.tar.gz |
MFC r267710:
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.
Diffstat (limited to 'sys/kern/kern_descrip.c')
-rw-r--r-- | sys/kern/kern_descrip.c | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/sys/kern/kern_descrip.c b/sys/kern/kern_descrip.c index 784446e..80a9c20 100644 --- a/sys/kern/kern_descrip.c +++ b/sys/kern/kern_descrip.c @@ -1235,7 +1235,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); @@ -2949,7 +2949,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; @@ -3059,7 +3059,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)); @@ -3430,7 +3430,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; @@ -3803,7 +3803,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); } @@ -3853,7 +3853,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); |