Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 3 Feb 2020 22:27:03 +0000 (UTC)
From:      Mateusz Guzik <mjg@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r357469 - head/sys/kern
Message-ID:  <202002032227.013MR3KI081555@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: mjg
Date: Mon Feb  3 22:27:03 2020
New Revision: 357469
URL: https://svnweb.freebsd.org/changeset/base/357469

Log:
  fd: remove the seq argument from fget routines
  
  It is almost always NULL.

Modified:
  head/sys/kern/kern_descrip.c

Modified: head/sys/kern/kern_descrip.c
==============================================================================
--- head/sys/kern/kern_descrip.c	Mon Feb  3 22:26:29 2020	(r357468)
+++ head/sys/kern/kern_descrip.c	Mon Feb  3 22:27:03 2020	(r357469)
@@ -2780,7 +2780,7 @@ fget_unlocked(struct filedesc *fdp, int fd, cap_rights
  */
 static __inline int
 _fget(struct thread *td, int fd, struct file **fpp, int flags,
-    cap_rights_t *needrightsp, seqc_t *seqp)
+    cap_rights_t *needrightsp)
 {
 	struct filedesc *fdp;
 	struct file *fp;
@@ -2788,7 +2788,7 @@ _fget(struct thread *td, int fd, struct file **fpp, in
 
 	*fpp = NULL;
 	fdp = td->td_proc->p_fd;
-	error = fget_unlocked(fdp, fd, needrightsp, &fp, seqp);
+	error = fget_unlocked(fdp, fd, needrightsp, &fp, NULL);
 	if (__predict_false(error != 0))
 		return (error);
 	if (__predict_false(fp->f_ops == &badfileops)) {
@@ -2830,7 +2830,7 @@ int
 fget(struct thread *td, int fd, cap_rights_t *rightsp, struct file **fpp)
 {
 
-	return (_fget(td, fd, fpp, 0, rightsp, NULL));
+	return (_fget(td, fd, fpp, 0, rightsp));
 }
 
 int
@@ -2839,19 +2839,24 @@ fget_mmap(struct thread *td, int fd, cap_rights_t *rig
 {
 	int error;
 #ifndef CAPABILITIES
-	error = _fget(td, fd, fpp, 0, rightsp, NULL);
+	error = _fget(td, fd, fpp, 0, rightsp);
 	if (maxprotp != NULL)
 		*maxprotp = VM_PROT_ALL;
 #else
 	cap_rights_t fdrights;
-	struct filedesc *fdp = td->td_proc->p_fd;
+	struct filedesc *fdp;
 	seqc_t seq;
 
+	fdp = td->td_proc->p_fd;
 	MPASS(cap_rights_is_set(rightsp, CAP_MMAP));
 	for (;;) {
-		error = _fget(td, fd, fpp, 0, rightsp, &seq);
-		if (error != 0)
+		error = fget_unlocked(fdp, fd, rightsp, fpp, &seq);
+		if (__predict_false(error != 0))
 			return (error);
+		if (__predict_false((*fpp)->f_ops == &badfileops)) {
+			fdrop(*fpp, td);
+			return (EBADF);
+		}
 		if (maxprotp != NULL)
 			fdrights = *cap_rights(fdp, fd);
 		if (!fd_modified(fdp, fd, seq))
@@ -2872,14 +2877,14 @@ int
 fget_read(struct thread *td, int fd, cap_rights_t *rightsp, struct file **fpp)
 {
 
-	return (_fget(td, fd, fpp, FREAD, rightsp, NULL));
+	return (_fget(td, fd, fpp, FREAD, rightsp));
 }
 
 int
 fget_write(struct thread *td, int fd, cap_rights_t *rightsp, struct file **fpp)
 {
 
-	return (_fget(td, fd, fpp, FWRITE, rightsp, NULL));
+	return (_fget(td, fd, fpp, FWRITE, rightsp));
 }
 
 int
@@ -2926,7 +2931,7 @@ _fgetvp(struct thread *td, int fd, int flags, cap_righ
 	int error;
 
 	*vpp = NULL;
-	error = _fget(td, fd, &fp, flags, needrightsp, NULL);
+	error = _fget(td, fd, &fp, flags, needrightsp);
 	if (error != 0)
 		return (error);
 	if (fp->f_vnode == NULL) {



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202002032227.013MR3KI081555>