Re: [PATCH] random: use symbolic constants for crng_init states

From: Joe Perches
Date: Sun May 08 2022 - 08:58:36 EST


On Sun, 2022-05-08 at 13:26 +0200, Jason A. Donenfeld wrote:
> crng_init represents a state machine, with three states, and various
> rules for transitions. For the longest time, we've been managing these
> with "0", "1", and "2", and expecting people to figure it out. To make
> the code more obvious, replace these with proper enum values
> representing the transition, and then redocument what each of these
> states mean.

good idea

> diff --git a/drivers/char/random.c b/drivers/char/random.c
[]
> @@ -72,16 +72,16 @@
[]
> -/* Various types of waiters for crng_init->2 transition. */
> +static enum {
> + CRNG_EMPTY = 0, /* Little to no entropy collected */
> + CRNG_EARLY = 1, /* At least POOL_EARLY_BITS collected */
> + CRNG_READY = 2 /* Fully iniitalized with POOL_READY_BITS collected */

typo: initialized

> enum {
> POOL_BITS = BLAKE2S_HASH_SIZE * 8,
> - POOL_INIT_BITS = POOL_BITS, /* No point in settling for less. */
> - POOL_FAST_INIT_BITS = POOL_INIT_BITS / 2
> + POOL_READY_BITS = POOL_BITS, /* When crng_init->CRNG_READY */
> + POOL_EARLY_BITS = POOL_READY_BITS / 2 /* When crng_init->CRNG_EARLY */

Seems odd to use a divisor with an enum