random: avoid checking crng_ready() twice in random_init()
authorJason A. Donenfeld <Jason@zx2c4.com>
Mon, 13 Jun 2022 08:07:47 +0000 (10:07 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 14 Jun 2022 16:36:27 +0000 (18:36 +0200)
commit 9b29b6b20376ab64e1b043df6301d8a92378e631 upstream.

The current flow expands to:

    if (crng_ready())
       ...
    else if (...)
        if (!crng_ready())
            ...

The second crng_ready() call is redundant, but can't so easily be
optimized out by the compiler.

This commit simplifies that to:

    if (crng_ready()
        ...
    else if (...)
        ...

Fixes: 560181c27b58 ("random: move initialization functions out of hot pages")
Cc: stable@vger.kernel.org
Cc: Dominik Brodowski <linux@dominikbrodowski.net>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/char/random.c

index 4ed2dc29f2343dff54dbb98eca1af241e050ed45..de45c7ec82773805c91bd0a045f247badc6b9fa1 100644 (file)
@@ -838,7 +838,7 @@ int __init random_init(const char *command_line)
        if (crng_ready())
                crng_reseed();
        else if (trust_cpu)
-               credit_init_bits(arch_bytes * 8);
+               _credit_init_bits(arch_bytes * 8);
 
        return 0;
 }