Skip to content

Commit 72e5c74

Browse files
Sebastian Andrzej Siewiortytso
authored andcommitted
random: reorder READ_ONCE() in get_random_uXX
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]>
1 parent eecabf5 commit 72e5c74

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

drivers/char/random.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2089,7 +2089,7 @@ static DEFINE_PER_CPU(struct batched_entropy, batched_entropy_u64);
20892089
u64 get_random_u64(void)
20902090
{
20912091
u64 ret;
2092-
bool use_lock = READ_ONCE(crng_init) < 2;
2092+
bool use_lock;
20932093
unsigned long flags = 0;
20942094
struct batched_entropy *batch;
20952095
static void *previous;
@@ -2105,6 +2105,7 @@ u64 get_random_u64(void)
21052105

21062106
warn_unseeded_randomness(&previous);
21072107

2108+
use_lock = READ_ONCE(crng_init) < 2;
21082109
batch = &get_cpu_var(batched_entropy_u64);
21092110
if (use_lock)
21102111
read_lock_irqsave(&batched_entropy_reset_lock, flags);
@@ -2124,7 +2125,7 @@ static DEFINE_PER_CPU(struct batched_entropy, batched_entropy_u32);
21242125
u32 get_random_u32(void)
21252126
{
21262127
u32 ret;
2127-
bool use_lock = READ_ONCE(crng_init) < 2;
2128+
bool use_lock;
21282129
unsigned long flags = 0;
21292130
struct batched_entropy *batch;
21302131
static void *previous;
@@ -2134,6 +2135,7 @@ u32 get_random_u32(void)
21342135

21352136
warn_unseeded_randomness(&previous);
21362137

2138+
use_lock = READ_ONCE(crng_init) < 2;
21372139
batch = &get_cpu_var(batched_entropy_u32);
21382140
if (use_lock)
21392141
read_lock_irqsave(&batched_entropy_reset_lock, flags);

0 commit comments

Comments
 (0)