Re: [PATCH v8 03/15] futex: Add basic infrastructure for local task local hash.

From: Peter Zijlstra
Date: Mon Feb 03 2025 - 09:37:03 EST


On Mon, Feb 03, 2025 at 02:59:23PM +0100, Sebastian Andrzej Siewior wrote:
> +static int futex_hash_allocate(unsigned int hash_slots)
> +{
> + struct futex_hash_bucket *fhb;
> + int i;
> +
> + if (current->mm->futex_hash_bucket)
> + return -EALREADY;
> +
> + if (!thread_group_leader(current))
> + return -EINVAL;
> +
> + if (hash_slots == 0)
> + hash_slots = 16;
> + if (hash_slots < 2)
> + hash_slots = 2;
> + if (hash_slots > 131072)
> + hash_slots = 131072;
> + if (!is_power_of_2(hash_slots))
> + hash_slots = rounddown_pow_of_two(hash_slots);

Why not require the argument is 2^n and fail otherwise?