alloc_fdtable(): change calling conventions.
authorAl Viro <viro@zeniv.linux.org.uk>
Wed, 7 Aug 2024 02:14:07 +0000 (22:14 -0400)
committerAl Viro <viro@zeniv.linux.org.uk>
Mon, 7 Oct 2024 17:34:41 +0000 (13:34 -0400)
commit1d3b4bec3ce55e0c46cdce7d0402dbd6b4af3a3d
treeeecf8973805e3b17b6b55cf95189b97e1cf5822b
parent0c40bf47cf2d9e1413b1e62826c89c2341e66e40
alloc_fdtable(): change calling conventions.

First of all, tell it how many slots do we want, not which slot
is wanted.  It makes one caller (dup_fd()) more straightforward
and doesn't harm another (expand_fdtable()).

Furthermore, make it return ERR_PTR() on failure rather than
returning NULL.  Simplifies the callers.

Simplify the size calculation, while we are at it - note that we
always have slots_wanted greater than BITS_PER_LONG.  What the
rules boil down to is
* use the smallest power of two large enough to give us
that many slots
* on 32bit skip 64 and 128 - the minimal capacity we want
there is 256 slots (i.e. 1Kb fd array).
* on 64bit don't skip anything, the minimal capacity is
128 - and we'll never be asked for 64 or less.  128 slots means
1Kb fd array, again.
* on 128bit, if that ever happens, don't skip anything -
we'll never be asked for 128 or less, so the fd array allocation
will be at least 2Kb.

Reviewed-by: Christian Brauner <brauner@kernel.org>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
fs/file.c