Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 27 Jun 2006 00:49:32 GMT
From:      Kip Macy <kmacy@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 100107 for review
Message-ID:  <200606270049.k5R0nWp5060101@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=100107

Change 100107 by kmacy@kmacy_storage:sun4v_work_sleepq on 2006/06/27 00:48:36

	move out error checking out of the lock held path in _fget

Affected files ...

.. //depot/projects/kmacy_sun4v/src/sys/kern/kern_descrip.c#9 edit

Differences ...

==== //depot/projects/kmacy_sun4v/src/sys/kern/kern_descrip.c#9 (text+ko) ====

@@ -1965,30 +1965,35 @@
 	if (td == NULL || (fdp = td->td_proc->p_fd) == NULL)
 		return (EBADF);
 	FILEDESC_LOCK(fdp);
-	if ((fp = fget_locked(fdp, fd)) == NULL || fp->f_ops == &badfileops) {
+	if ((fp = fget_locked(fdp, fd)) == NULL) {
+		hold = 0;
+		goto fail;
+	}
+	if (hold) {
+		fhold(fp);
 		FILEDESC_UNLOCK(fdp);
-		return (EBADF);
 	}
-
+	*fpp = fp;
+	if (fp->f_ops == &badfileops) 
+		goto fail;
 	/*
 	 * FREAD and FWRITE failure return EBADF as per POSIX.
 	 *
 	 * Only one flag, or 0, may be specified.
 	 */
-	if (flags == FREAD && (fp->f_flag & FREAD) == 0) {
+	if (flags == FREAD && (fp->f_flag & FREAD) == 0) 
+		goto fail;
+	if (flags == FWRITE && (fp->f_flag & FWRITE) == 0) 
+		goto fail;
+	return (0);
+ fail:
+	if (hold) {
+		FILEDESC_LOCK(fdp);
+		fdrop(fp, curthread);
 		FILEDESC_UNLOCK(fdp);
-		return (EBADF);
-	}
-	if (flags == FWRITE && (fp->f_flag & FWRITE) == 0) {
+	} else
 		FILEDESC_UNLOCK(fdp);
-		return (EBADF);
-	}
-	if (hold) {
-		fhold(fp);
-		FILEDESC_UNLOCK(fdp);
-	}
-	*fpp = fp;
-	return (0);
+	return (EBADF);
 }
 
 int



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