Re: [PATCH] random: make consistent usage of crng_ready()

From: Jason A. Donenfeld
Date: Sat Mar 12 2022 - 18:58:28 EST


Hi Eric,

On Sat, Mar 12, 2022 at 1:09 PM Eric Biggers <ebiggers@xxxxxxxxxx> wrote:
>
> On Tue, Mar 08, 2022 at 11:25:17AM -0700, Jason A. Donenfeld wrote:
> > diff --git a/drivers/char/random.c b/drivers/char/random.c
> > index 69591d599338..e37ae7ef039c 100644
> > --- a/drivers/char/random.c
> > +++ b/drivers/char/random.c
> > @@ -123,7 +123,7 @@ static void try_to_generate_entropy(void);
> > */
> > int wait_for_random_bytes(void)
> > {
> > - if (likely(crng_ready()))
> > + if (crng_ready())
> > return 0;
> >
> > do {
> ...
> > } while (!crng_ready());
>
> I guess the reason why the above doesn't simply use a 'while' loop is because
> someone wanted 'likely()' on the first crng_ready()? That doesn't actually
> apply, since crng_ready() has likely() itself, it should just be a 'while' loop.

Nice catch, thanks.

Jason