From owner-svn-src-stable-10@FreeBSD.ORG Sun Jul 6 22:54:18 2014 Return-Path: Delivered-To: svn-src-stable-10@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 937CBA0E; Sun, 6 Jul 2014 22:54:18 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 805982DB4; Sun, 6 Jul 2014 22:54:18 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.8/8.14.8) with ESMTP id s66MsI4H072912; Sun, 6 Jul 2014 22:54:18 GMT (envelope-from mjg@svn.freebsd.org) Received: (from mjg@localhost) by svn.freebsd.org (8.14.8/8.14.8/Submit) id s66MsHHv072908; Sun, 6 Jul 2014 22:54:17 GMT (envelope-from mjg@svn.freebsd.org) Message-Id: <201407062254.s66MsHHv072908@svn.freebsd.org> From: Mateusz Guzik Date: Sun, 6 Jul 2014 22:54:17 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r268338 - in stable/10/sys: kern sys X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-10@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 06 Jul 2014 22:54:18 -0000 Author: mjg Date: Sun Jul 6 22:54:17 2014 New Revision: 268338 URL: http://svnweb.freebsd.org/changeset/base/268338 Log: 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. Modified: stable/10/sys/kern/kern_descrip.c stable/10/sys/kern/sys_generic.c stable/10/sys/kern/vfs_syscalls.c stable/10/sys/sys/filedesc.h Modified: stable/10/sys/kern/kern_descrip.c ============================================================================== --- stable/10/sys/kern/kern_descrip.c Sun Jul 6 22:51:53 2014 (r268337) +++ stable/10/sys/kern/kern_descrip.c Sun Jul 6 22:54:17 2014 (r268338) @@ -1235,7 +1235,7 @@ sys_closefrom(struct thread *td, struct 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_HANDLE 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, 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); Modified: stable/10/sys/kern/sys_generic.c ============================================================================== --- stable/10/sys/kern/sys_generic.c Sun Jul 6 22:51:53 2014 (r268337) +++ stable/10/sys/kern/sys_generic.c Sun Jul 6 22:54:17 2014 (r268338) @@ -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) { Modified: stable/10/sys/kern/vfs_syscalls.c ============================================================================== --- stable/10/sys/kern/vfs_syscalls.c Sun Jul 6 22:51:53 2014 (r268337) +++ stable/10/sys/kern/vfs_syscalls.c Sun Jul 6 22:54:17 2014 (r268338) @@ -829,7 +829,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; Modified: stable/10/sys/sys/filedesc.h ============================================================================== --- stable/10/sys/sys/filedesc.h Sun Jul 6 22:51:53 2014 (r268337) +++ stable/10/sys/sys/filedesc.h Sun Jul 6 22:54:17 2014 (r268338) @@ -176,7 +176,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);