summaryrefslogtreecommitdiff
path: root/drivers
diff options
context:
space:
mode:
authorSebastian Andrzej Siewior <bigeasy@linutronix.de>2017-06-30 16:37:13 +0200
committerTheodore Ts'o <tytso@mit.edu>2017-07-15 12:33:22 -0400
commit72e5c740f6335e27253b8ff64d23d00337091535 (patch)
tree277b0d7fdd627c80c54deafae9ab10b27c3d39de /drivers
parenteecabf567422eda02bd179f2707d8fe24f52d888 (diff)
random: reorder READ_ONCE() in get_random_uXX
Avoid the READ_ONCE in commit 4a072c71f49b ("random: silence compiler warnings and fix race") if we can leave the function after arch_get_random_XXX(). Cc: Jason A. Donenfeld <Jason@zx2c4.com> Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/char/random.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/drivers/char/random.c b/drivers/char/random.c
index 799d37981d99..05d255e1c112 100644
--- a/drivers/char/random.c
+++ b/drivers/char/random.c
@@ -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;
@@ -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);
@@ -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;
@@ -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);