Skip to content

Commit

Permalink
random: reorder READ_ONCE() in get_random_uXX
Browse files Browse the repository at this point in the history
Avoid the READ_ONCE in commit 4a072c7 ("random: silence compiler
warnings and fix race") if we can leave the function after
arch_get_random_XXX().

Cc: Jason A. Donenfeld <[email protected]>
Signed-off-by: Sebastian Andrzej Siewior <[email protected]>
Signed-off-by: Theodore Ts'o <[email protected]>
  • Loading branch information
Sebastian Andrzej Siewior authored and tytso committed Jul 15, 2017
1 parent eecabf5 commit 72e5c74
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions drivers/char/random.c
Original file line number Diff line number Diff line change
Expand Up @@ -2089,7 +2089,7 @@ static DEFINE_PER_CPU(struct batched_entropy, batched_entropy_u64);
u64 get_random_u64(void)
{
u64 ret;
bool use_lock = READ_ONCE(crng_init) < 2;
bool use_lock;
unsigned long flags = 0;
struct batched_entropy *batch;
static void *previous;
Expand All @@ -2105,6 +2105,7 @@ u64 get_random_u64(void)

warn_unseeded_randomness(&previous);

use_lock = READ_ONCE(crng_init) < 2;
batch = &get_cpu_var(batched_entropy_u64);
if (use_lock)
read_lock_irqsave(&batched_entropy_reset_lock, flags);
Expand All @@ -2124,7 +2125,7 @@ static DEFINE_PER_CPU(struct batched_entropy, batched_entropy_u32);
u32 get_random_u32(void)
{
u32 ret;
bool use_lock = READ_ONCE(crng_init) < 2;
bool use_lock;
unsigned long flags = 0;
struct batched_entropy *batch;
static void *previous;
Expand All @@ -2134,6 +2135,7 @@ u32 get_random_u32(void)

warn_unseeded_randomness(&previous);

use_lock = READ_ONCE(crng_init) < 2;
batch = &get_cpu_var(batched_entropy_u32);
if (use_lock)
read_lock_irqsave(&batched_entropy_reset_lock, flags);
Expand Down

0 comments on commit 72e5c74

Please sign in to comment.