aboutsummaryrefslogtreecommitdiff
path: root/drivers/char/random.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/char/random.c')
-rw-r--r--drivers/char/random.c19
1 files changed, 7 insertions, 12 deletions
diff --git a/drivers/char/random.c b/drivers/char/random.c
index 50973a074d2d..19a602c69f2f 100644
--- a/drivers/char/random.c
+++ b/drivers/char/random.c
@@ -122,18 +122,13 @@ static void try_to_generate_entropy(void);
*/
int wait_for_random_bytes(void)
{
- if (likely(crng_ready()))
- return 0;
-
- do {
+ while (!crng_ready()) {
int ret;
ret = wait_event_interruptible_timeout(crng_init_wait, crng_ready(), HZ);
if (ret)
return ret > 0 ? 0 : ret;
-
try_to_generate_entropy();
- } while (!crng_ready());
-
+ }
return 0;
}
EXPORT_SYMBOL(wait_for_random_bytes);
@@ -288,7 +283,7 @@ static void crng_reseed(bool force)
++next_gen;
WRITE_ONCE(base_crng.generation, next_gen);
WRITE_ONCE(base_crng.birth, jiffies);
- if (crng_init < 2) {
+ if (!crng_ready()) {
crng_init = 2;
finalize_init = true;
}
@@ -351,7 +346,7 @@ static void crng_make_state(u32 chacha_state[CHACHA_STATE_WORDS],
* ready, we do fast key erasure with the base_crng directly, because
* this is what crng_pre_init_inject() mutates during early init.
*/
- if (unlikely(!crng_ready())) {
+ if (!crng_ready()) {
bool ready;
spin_lock_irqsave(&base_crng.lock, flags);
@@ -794,7 +789,7 @@ static void credit_entropy_bits(size_t nbits)
entropy_count = min_t(unsigned int, POOL_BITS, orig + add);
} while (cmpxchg(&input_pool.entropy_count, orig, entropy_count) != orig);
- if (crng_init < 2 && entropy_count >= POOL_MIN_BITS)
+ if (!crng_ready() && entropy_count >= POOL_MIN_BITS)
crng_reseed(false);
}
@@ -956,7 +951,7 @@ int __init rand_initialize(void)
extract_entropy(base_crng.key, sizeof(base_crng.key));
++base_crng.generation;
- if (arch_init && trust_cpu && crng_init < 2) {
+ if (arch_init && trust_cpu && !crng_ready()) {
crng_init = 2;
pr_notice("crng init done (trusting CPU's manufacturer)\n");
}
@@ -1558,7 +1553,7 @@ static long random_ioctl(struct file *f, unsigned int cmd, unsigned long arg)
case RNDRESEEDCRNG:
if (!capable(CAP_SYS_ADMIN))
return -EPERM;
- if (crng_init < 2)
+ if (!crng_ready())
return -ENODATA;
crng_reseed(false);
return 0;