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

From: Jason A. Donenfeld
Date: Sun May 08 2022 - 15:05:48 EST


On Sun, May 08, 2022 at 05:57:18AM -0700, Joe Perches wrote:
> > 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

Thanks, will do.

>
> > 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

Why? The constants are defined in terms of other constants.

Jason