From ecb991e675416271c1bf87cc6f33567fd19f536e Mon Sep 17 00:00:00 2001 From: mjg Date: Mon, 3 Feb 2020 22:27:55 +0000 Subject: [PATCH] fd: remove the seq argument from fget_unlocked It is almost always NULL. --- .../linuxkpi/common/include/linux/file.h | 6 ++-- sys/kern/kern_descrip.c | 30 +++++++++---------- sys/kern/sys_generic.c | 2 +- sys/kern/tty.c | 2 +- sys/kern/vfs_syscalls.c | 2 +- sys/sys/filedesc.h | 4 ++- 6 files changed, 24 insertions(+), 22 deletions(-) diff --git a/sys/compat/linuxkpi/common/include/linux/file.h b/sys/compat/linuxkpi/common/include/linux/file.h index acbb43bac1b..21b254211cf 100644 --- a/sys/compat/linuxkpi/common/include/linux/file.h +++ b/sys/compat/linuxkpi/common/include/linux/file.h @@ -54,7 +54,7 @@ linux_fget(unsigned int fd) /* lookup file pointer by file descriptor index */ if (fget_unlocked(curthread->td_proc->p_fd, fd, - &cap_no_rights, &file, NULL) != 0) + &cap_no_rights, &file) != 0) return (NULL); /* check if file handle really belongs to us */ @@ -90,7 +90,7 @@ put_unused_fd(unsigned int fd) struct file *file; if (fget_unlocked(curthread->td_proc->p_fd, fd, - &cap_no_rights, &file, NULL) != 0) { + &cap_no_rights, &file) != 0) { return; } /* @@ -110,7 +110,7 @@ fd_install(unsigned int fd, struct linux_file *filp) struct file *file; if (fget_unlocked(curthread->td_proc->p_fd, fd, - &cap_no_rights, &file, NULL) != 0) { + &cap_no_rights, &file) != 0) { filp->_file = NULL; } else { filp->_file = file; diff --git a/sys/kern/kern_descrip.c b/sys/kern/kern_descrip.c index 80d3c534c80..401068517d8 100644 --- a/sys/kern/kern_descrip.c +++ b/sys/kern/kern_descrip.c @@ -619,7 +619,7 @@ kern_fcntl(struct thread *td, int fd, int cmd, intptr_t arg) break; } - error = fget_unlocked(fdp, fd, &cap_flock_rights, &fp, NULL); + error = fget_unlocked(fdp, fd, &cap_flock_rights, &fp); if (error != 0) break; if (fp->f_type != DTYPE_VNODE) { @@ -706,7 +706,7 @@ kern_fcntl(struct thread *td, int fd, int cmd, intptr_t arg) * that the closing thread was a bit slower and that the * advisory lock succeeded before the close. */ - error = fget_unlocked(fdp, fd, &cap_no_rights, &fp2, NULL); + error = fget_unlocked(fdp, fd, &cap_no_rights, &fp2); if (error != 0) { fdrop(fp, td); break; @@ -724,7 +724,7 @@ kern_fcntl(struct thread *td, int fd, int cmd, intptr_t arg) break; case F_GETLK: - error = fget_unlocked(fdp, fd, &cap_flock_rights, &fp, NULL); + error = fget_unlocked(fdp, fd, &cap_flock_rights, &fp); if (error != 0) break; if (fp->f_type != DTYPE_VNODE) { @@ -758,7 +758,7 @@ kern_fcntl(struct thread *td, int fd, int cmd, intptr_t arg) break; case F_ADD_SEALS: - error = fget_unlocked(fdp, fd, &cap_no_rights, &fp, NULL); + error = fget_unlocked(fdp, fd, &cap_no_rights, &fp); if (error != 0) break; error = fo_add_seals(fp, arg); @@ -766,7 +766,7 @@ kern_fcntl(struct thread *td, int fd, int cmd, intptr_t arg) break; case F_GET_SEALS: - error = fget_unlocked(fdp, fd, &cap_no_rights, &fp, NULL); + error = fget_unlocked(fdp, fd, &cap_no_rights, &fp); if (error != 0) break; if (fo_get_seals(fp, &seals) == 0) @@ -780,7 +780,7 @@ kern_fcntl(struct thread *td, int fd, int cmd, intptr_t arg) arg = arg ? 128 * 1024: 0; /* FALLTHROUGH */ case F_READAHEAD: - error = fget_unlocked(fdp, fd, &cap_no_rights, &fp, NULL); + error = fget_unlocked(fdp, fd, &cap_no_rights, &fp); if (error != 0) break; if (fp->f_type != DTYPE_VNODE) { @@ -831,7 +831,7 @@ kern_fcntl(struct thread *td, int fd, int cmd, intptr_t arg) * horrible kludge facilitates the current behavior in a much * cheaper manner until someone(tm) sorts this out. */ - error = fget_unlocked(fdp, fd, &cap_no_rights, &fp, NULL); + error = fget_unlocked(fdp, fd, &cap_no_rights, &fp); if (error != 0) break; if (fp->f_type != DTYPE_VNODE) { @@ -2644,15 +2644,15 @@ fget_cap(struct thread *td, int fd, cap_rights_t *needrightsp, struct filedesc *fdp = td->td_proc->p_fd; int error; #ifndef CAPABILITIES - error = fget_unlocked(fdp, fd, needrightsp, fpp, NULL); - if (error == 0 && havecapsp != NULL) + error = fget_unlocked(fdp, fd, needrightsp, fpp); + if (havecapsp != NULL && error == 0) filecaps_fill(havecapsp); #else struct file *fp; seqc_t seq; for (;;) { - error = fget_unlocked(fdp, fd, needrightsp, &fp, &seq); + error = fget_unlocked_seq(fdp, fd, needrightsp, &fp, &seq); if (error != 0) return (error); @@ -2683,7 +2683,7 @@ fget_cap(struct thread *td, int fd, cap_rights_t *needrightsp, } int -fget_unlocked(struct filedesc *fdp, int fd, cap_rights_t *needrightsp, +fget_unlocked_seq(struct filedesc *fdp, int fd, cap_rights_t *needrightsp, struct file **fpp, seqc_t *seqp) { #ifdef CAPABILITIES @@ -2788,7 +2788,7 @@ _fget(struct thread *td, int fd, struct file **fpp, int flags, *fpp = NULL; fdp = td->td_proc->p_fd; - error = fget_unlocked(fdp, fd, needrightsp, &fp, NULL); + error = fget_unlocked(fdp, fd, needrightsp, &fp); if (__predict_false(error != 0)) return (error); if (__predict_false(fp->f_ops == &badfileops)) { @@ -2850,7 +2850,7 @@ fget_mmap(struct thread *td, int fd, cap_rights_t *rightsp, u_char *maxprotp, fdp = td->td_proc->p_fd; MPASS(cap_rights_is_set(rightsp, CAP_MMAP)); for (;;) { - error = fget_unlocked(fdp, fd, rightsp, fpp, &seq); + error = fget_unlocked_seq(fdp, fd, rightsp, fpp, &seq); if (__predict_false(error != 0)) return (error); if (__predict_false((*fpp)->f_ops == &badfileops)) { @@ -2893,14 +2893,14 @@ fget_fcntl(struct thread *td, int fd, cap_rights_t *rightsp, int needfcntl, { struct filedesc *fdp = td->td_proc->p_fd; #ifndef CAPABILITIES - return (fget_unlocked(fdp, fd, rightsp, fpp, NULL)); + return (fget_unlocked(fdp, fd, rightsp, fpp)); #else int error; seqc_t seq; MPASS(cap_rights_is_set(rightsp, CAP_FCNTL)); for (;;) { - error = fget_unlocked(fdp, fd, rightsp, fpp, &seq); + error = fget_unlocked_seq(fdp, fd, rightsp, fpp, &seq); if (error != 0) return (error); error = cap_fcntl_check(fdp, fd, needfcntl); diff --git a/sys/kern/sys_generic.c b/sys/kern/sys_generic.c index c013e6832b7..9cbf7138b00 100644 --- a/sys/kern/sys_generic.c +++ b/sys/kern/sys_generic.c @@ -1245,7 +1245,7 @@ static __inline int getselfd_cap(struct filedesc *fdp, int fd, struct file **fpp) { - return (fget_unlocked(fdp, fd, &cap_event_rights, fpp, NULL)); + return (fget_unlocked(fdp, fd, &cap_event_rights, fpp)); } /* diff --git a/sys/kern/tty.c b/sys/kern/tty.c index d8e893db4b2..77e268c451a 100644 --- a/sys/kern/tty.c +++ b/sys/kern/tty.c @@ -2059,7 +2059,7 @@ ttyhook_register(struct tty **rtp, struct proc *p, int fd, struct ttyhook *th, /* Validate the file descriptor. */ fdp = p->p_fd; error = fget_unlocked(fdp, fd, cap_rights_init(&rights, CAP_TTYHOOK), - &fp, NULL); + &fp); if (error != 0) return (error); if (fp->f_ops == &badfileops) { diff --git a/sys/kern/vfs_syscalls.c b/sys/kern/vfs_syscalls.c index c22cb8662ea..a77018a778a 100644 --- a/sys/kern/vfs_syscalls.c +++ b/sys/kern/vfs_syscalls.c @@ -4173,7 +4173,7 @@ getvnode(struct thread *td, int fd, cap_rights_t *rightsp, struct file **fpp) struct file *fp; int error; - error = fget_unlocked(td->td_proc->p_fd, fd, rightsp, &fp, NULL); + error = fget_unlocked(td->td_proc->p_fd, fd, rightsp, &fp); if (error != 0) return (error); diff --git a/sys/sys/filedesc.h b/sys/sys/filedesc.h index 9dcc311da29..1f8dd5b1e3c 100644 --- a/sys/sys/filedesc.h +++ b/sys/sys/filedesc.h @@ -204,8 +204,10 @@ int fget_cap(struct thread *td, int fd, cap_rights_t *needrightsp, struct file **fpp, struct filecaps *havecapsp); /* Return a referenced file from an unlocked descriptor. */ -int fget_unlocked(struct filedesc *fdp, int fd, cap_rights_t *needrightsp, +int fget_unlocked_seq(struct filedesc *fdp, int fd, cap_rights_t *needrightsp, struct file **fpp, seqc_t *seqp); +#define fget_unlocked(fdp, fd, needrightsp, fpp) \ + fget_unlocked_seq(fdp, fd, needrightsp, fpp, NULL) /* Requires a FILEDESC_{S,X}LOCK held and returns without a ref. */ static __inline struct file * -- 2.45.0