aboutsummaryrefslogtreecommitdiff
path: root/fs/file.c
diff options
context:
space:
mode:
authorGravatar Yuntao Wang <yuntao.wang@linux.dev> 2024-05-30 00:06:56 +0800
committerGravatar Christian Brauner <brauner@kernel.org> 2024-05-30 09:11:47 +0200
commited8c7fbdfe117abbef81f65428ba263118ef298a (patch)
treecd0a4971a4bba159285a7a1a3e0a612bc2750037 /fs/file.c
parentMerge patch series "cachefiles: some bugfixes and cleanups for ondemand reque... (diff)
downloadlinux-ed8c7fbdfe117abbef81f65428ba263118ef298a.tar.gz
linux-ed8c7fbdfe117abbef81f65428ba263118ef298a.tar.bz2
linux-ed8c7fbdfe117abbef81f65428ba263118ef298a.zip
fs/file: fix the check in find_next_fd()
The maximum possible return value of find_next_zero_bit(fdt->full_fds_bits, maxbit, bitbit) is maxbit. This return value, multiplied by BITS_PER_LONG, gives the value of bitbit, which can never be greater than maxfd, it can only be equal to maxfd at most, so the following check 'if (bitbit > maxfd)' will never be true. Moreover, when bitbit equals maxfd, it indicates that there are no unused fds, and the function can directly return. Fix this check. Signed-off-by: Yuntao Wang <yuntao.wang@linux.dev> Link: https://lore.kernel.org/r/20240529160656.209352-1-yuntao.wang@linux.dev Reviewed-by: Jan Kara <jack@suse.cz> Signed-off-by: Christian Brauner <brauner@kernel.org>
Diffstat (limited to 'fs/file.c')
-rw-r--r--fs/file.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/fs/file.c b/fs/file.c
index 8076aef9c210..a3b72aa64f11 100644
--- a/fs/file.c
+++ b/fs/file.c
@@ -486,12 +486,12 @@ struct files_struct init_files = {
static unsigned int find_next_fd(struct fdtable *fdt, unsigned int start)
{
- unsigned int maxfd = fdt->max_fds;
+ unsigned int maxfd = fdt->max_fds; /* always multiple of BITS_PER_LONG */
unsigned int maxbit = maxfd / BITS_PER_LONG;
unsigned int bitbit = start / BITS_PER_LONG;
bitbit = find_next_zero_bit(fdt->full_fds_bits, maxbit, bitbit) * BITS_PER_LONG;
- if (bitbit > maxfd)
+ if (bitbit >= maxfd)
return maxfd;
if (bitbit > start)
start = bitbit;