svn commit: r341219 - in head/sys: kern sys
Mateusz Guzik
mjg at FreeBSD.org
Thu Nov 29 08:53:40 UTC 2018
Author: mjg
Date: Thu Nov 29 08:53:39 2018
New Revision: 341219
URL: https://svnweb.freebsd.org/changeset/base/341219
Log:
fd: unify fd range check across the routines
While here annotate out of range as unlikely.
Sponsored by: The FreeBSD Foundation
Modified:
head/sys/kern/kern_descrip.c
head/sys/sys/filedesc.h
Modified: head/sys/kern/kern_descrip.c
==============================================================================
--- head/sys/kern/kern_descrip.c Thu Nov 29 08:37:33 2018 (r341218)
+++ head/sys/kern/kern_descrip.c Thu Nov 29 08:53:39 2018 (r341219)
@@ -2637,7 +2637,7 @@ fget_unlocked(struct filedesc *fdp, int fd, cap_rights
#endif
fdt = fdp->fd_files;
- if ((u_int)fd >= fdt->fdt_nfiles)
+ if (__predict_false((u_int)fd >= fdt->fdt_nfiles))
return (EBADF);
/*
* Fetch the descriptor locklessly. We avoid fdrop() races by
Modified: head/sys/sys/filedesc.h
==============================================================================
--- head/sys/sys/filedesc.h Thu Nov 29 08:37:33 2018 (r341218)
+++ head/sys/sys/filedesc.h Thu Nov 29 08:53:39 2018 (r341219)
@@ -208,7 +208,7 @@ fget_locked(struct filedesc *fdp, int fd)
FILEDESC_LOCK_ASSERT(fdp);
- if (fd < 0 || fd > fdp->fd_lastfile)
+ if (__predict_false((u_int)fd >= fdp->fd_nfiles))
return (NULL);
return (fdp->fd_ofiles[fd].fde_file);
@@ -221,11 +221,11 @@ fdeget_locked(struct filedesc *fdp, int fd)
FILEDESC_LOCK_ASSERT(fdp);
- if (fd < 0 || fd > fdp->fd_lastfile)
+ if (__predict_false((u_int)fd >= fdp->fd_nfiles))
return (NULL);
fde = &fdp->fd_ofiles[fd];
- if (fde->fde_file == NULL)
+ if (__predict_false(fde->fde_file == NULL))
return (NULL);
return (fde);
More information about the svn-src-head
mailing list