Re: [PATCH] fs/file: fix the check in find_next_fd()

From: Christian Brauner
Date: Thu May 30 2024 - 03:13:08 EST


On Thu, 30 May 2024 00:06:56 +0800, Yuntao Wang wrote:
> 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.
>
> [...]

Comment added as that's really useful in general.

---

Applied to the vfs.fixes branch of the vfs/vfs.git tree.
Patches in the vfs.fixes branch should appear in linux-next soon.

Please report any outstanding bugs that were missed during review in a
new review to the original patch series allowing us to drop it.

It's encouraged to provide Acked-bys and Reviewed-bys even though the
patch has now been applied. If possible patch trailers will be updated.

Note that commit hashes shown below are subject to change due to rebase,
trailer updates or similar. If in doubt, please check the listed branch.

tree: https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git
branch: vfs.fixes

[1/1] fs/file: fix the check in find_next_fd()
https://git.kernel.org/vfs/vfs/c/96998332ac4d