random: do not use jump labels before they are initialized
[platform/kernel/linux-rpi.git] / drivers / char / random.c
index e2f1fce..136c671 100644 (file)
@@ -727,7 +727,8 @@ static void __cold _credit_init_bits(size_t bits)
 
        if (orig < POOL_READY_BITS && new >= POOL_READY_BITS) {
                crng_reseed(); /* Sets crng_init to CRNG_READY under base_crng.lock. */
-               execute_in_process_context(crng_set_ready, &set_ready);
+               if (static_key_initialized)
+                       execute_in_process_context(crng_set_ready, &set_ready);
                process_random_ready_list();
                wake_up_interruptible(&crng_init_wait);
                kill_fasync(&fasync, SIGIO, POLL_IN);
@@ -843,6 +844,14 @@ int __init random_init(const char *command_line)
        _mix_pool_bytes(command_line, strlen(command_line));
        add_latent_entropy();
 
+       /*
+        * If we were initialized by the bootloader before jump labels are
+        * initialized, then we should enable the static branch here, where
+        * it's guaranteed that jump labels have been initialized.
+        */
+       if (!static_branch_likely(&crng_is_ready) && crng_init >= CRNG_READY)
+               crng_set_ready(NULL);
+
        if (crng_ready())
                crng_reseed();
        else if (trust_cpu)