On Mon, Aug 12, 2024 at 07:44:26AM GMT, Al Viro wrote: > 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. > > Signed-off-by: Al Viro <viro@xxxxxxxxxxxxxxxxxx> > --- I'd copy the rules from the commit message into the function comment (Maybe not the 128bits part). Reviewed-by: Christian Brauner <brauner@xxxxxxxxxx>