fd: unify fd range check across the routines

While here annotate out of range as unlikely.

Sponsored by:	The FreeBSD Foundation
This commit is contained in:
Mateusz Guzik 2018-11-29 08:53:39 +00:00
parent 159dcc30a5
commit d47f3fdb0a
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=341219
2 changed files with 4 additions and 4 deletions

View File

@ -2637,7 +2637,7 @@ fget_unlocked(struct filedesc *fdp, int fd, cap_rights_t *needrightsp,
#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

View File

@ -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);