1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-12-19 10:53:58 +00:00

Simplify the code by making more use of the fdtofp() function.

MFC after:	1 month
This commit is contained in:
Pawel Jakub Dawidek 2012-06-14 15:37:15 +00:00
parent 215aeba939
commit 1a94dc8581
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=237077

View File

@ -679,8 +679,7 @@ kern_fcntl(struct thread *td, int fd, int cmd, intptr_t arg)
vfslocked = 0; vfslocked = 0;
/* Check for race with close */ /* Check for race with close */
FILEDESC_SLOCK(fdp); FILEDESC_SLOCK(fdp);
if (fd < 0 || fd >= fdp->fd_nfiles || if (fdtofp(fd, fdp) != fp) {
fp != fdp->fd_ofiles[fd]) {
FILEDESC_SUNLOCK(fdp); FILEDESC_SUNLOCK(fdp);
flp->l_whence = SEEK_SET; flp->l_whence = SEEK_SET;
flp->l_start = 0; flp->l_start = 0;
@ -822,7 +821,7 @@ do_dup(struct thread *td, int flags, int old, int new,
return (flags & DUP_FCNTL ? EINVAL : EBADF); return (flags & DUP_FCNTL ? EINVAL : EBADF);
FILEDESC_XLOCK(fdp); FILEDESC_XLOCK(fdp);
if (old >= fdp->fd_nfiles || fdp->fd_ofiles[old] == NULL) { if (fdtofp(old, fdp) == NULL) {
FILEDESC_XUNLOCK(fdp); FILEDESC_XUNLOCK(fdp);
return (EBADF); return (EBADF);
} }
@ -1201,8 +1200,7 @@ kern_close(td, fd)
AUDIT_SYSCLOSE(td, fd); AUDIT_SYSCLOSE(td, fd);
FILEDESC_XLOCK(fdp); FILEDESC_XLOCK(fdp);
if (fd < 0 || fd >= fdp->fd_nfiles || if ((fp = fdtofp(fd, fdp)) == NULL) {
(fp = fdp->fd_ofiles[fd]) == NULL) {
FILEDESC_XUNLOCK(fdp); FILEDESC_XUNLOCK(fdp);
return (EBADF); return (EBADF);
} }
@ -2596,8 +2594,7 @@ dupfdopen(struct thread *td, struct filedesc *fdp, int dfd, int mode, int opener
* closed, then reject. * closed, then reject.
*/ */
FILEDESC_XLOCK(fdp); FILEDESC_XLOCK(fdp);
if (dfd < 0 || dfd >= fdp->fd_nfiles || if ((fp = fdtofp(dfd, fdp)) == NULL) {
(fp = fdp->fd_ofiles[dfd]) == NULL) {
FILEDESC_XUNLOCK(fdp); FILEDESC_XUNLOCK(fdp);
return (EBADF); return (EBADF);
} }