[RFC PATCH v1 20/50] lib/random32: Move prandom_warmup() inside prandom_seed_early()

From: George Spelvin
Date: Sat Mar 28 2020 - 12:45:02 EST


They're always called as a pair, so shrink the code.

Also, unrolling prandom_warmup() is just a waste of code space.
Write it as a loop.

Signed-off-by: George Spelvin <lkml@xxxxxxx>
Cc: Daniel Borkmann <daniel@xxxxxxxxxxxxx>
Cc: Stephen Hemminger <stephen@xxxxxxxxxxxxxxxxxx>
Cc: Hannes Frederic Sowa <hannes@xxxxxxxxxxxxxxxxxxx>
---
lib/random32.c | 17 ++++-------------
1 file changed, 4 insertions(+), 13 deletions(-)

diff --git a/lib/random32.c b/lib/random32.c
index fc369f4e550c2..340696decc3bb 100644
--- a/lib/random32.c
+++ b/lib/random32.c
@@ -138,17 +138,10 @@ EXPORT_SYMBOL(prandom_bytes);

static void prandom_warmup(struct rnd_state *state)
{
+ int i;
/* Calling RNG ten times to satisfy recurrence condition */
- prandom_u32_state(state);
- prandom_u32_state(state);
- prandom_u32_state(state);
- prandom_u32_state(state);
- prandom_u32_state(state);
- prandom_u32_state(state);
- prandom_u32_state(state);
- prandom_u32_state(state);
- prandom_u32_state(state);
- prandom_u32_state(state);
+ for (i = 0; i < 10; i++)
+ prandom_u32_state(state);
}

static u32 __extract_hwseed(void)
@@ -170,6 +163,7 @@ static void prandom_seed_early(struct rnd_state *state, u32 seed,
state->s2 = __seed(HWSEED() ^ LCG(state->s1), 8U);
state->s3 = __seed(HWSEED() ^ LCG(state->s2), 16U);
state->s4 = __seed(HWSEED() ^ LCG(state->s3), 128U);
+ prandom_warmup(state);
}

/**
@@ -209,7 +203,6 @@ static int __init prandom_init(void)
u32 weak_seed = (i + jiffies) ^ random_get_entropy();

prandom_seed_early(state, weak_seed, true);
- prandom_warmup(state);
}

return 0;
@@ -433,7 +426,6 @@ static void __init prandom_state_selftest(void)
struct rnd_state state;

prandom_seed_early(&state, test1[i].seed, false);
- prandom_warmup(&state);

if (test1[i].result != prandom_u32_state(&state))
error = true;
@@ -448,7 +440,6 @@ static void __init prandom_state_selftest(void)
struct rnd_state state;

prandom_seed_early(&state, test2[i].seed, false);
- prandom_warmup(&state);

for (j = 0; j < test2[i].iteration - 1; j++)
prandom_u32_state(&state);
--
2.26.0