lkml.org 
[lkml]   [2014]   [Jun]   [7]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
Subject[PATCH 2/7] lib/random32.c: Remove excess calls to prandom_u32_state in initialization
Unrolling code in single-use code paths is just silly.  There are two
instances:

1) prandom_warmup() calls 10 times.
2) prandom_state_selftest() can avoid one call and simplify the
loop logic by repeating an assignment to a local variable
(that probably adds zero code anyway)

Signed-off-by: George Spelvin <linux@horizon.com>
---
lib/random32.c | 21 ++++++++-------------
1 file changed, 8 insertions(+), 13 deletions(-)

diff --git a/lib/random32.c b/lib/random32.c
index 4da5d281..2e7c15c0 100644
--- a/lib/random32.c
+++ b/lib/random32.c
@@ -134,17 +134,11 @@ EXPORT_SYMBOL(prandom_bytes);

static void prandom_warmup(struct rnd_state *state)
{
+ int i;
+
/* Calling RNG ten times to satify 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 void prandom_seed_very_weak(struct rnd_state *state, u32 seed)
@@ -433,14 +427,15 @@ static void __init prandom_state_selftest(void)

for (i = 0; i < ARRAY_SIZE(test2); i++) {
struct rnd_state state;
+ u32 result;

prandom_seed_very_weak(&state, test2[i].seed);
prandom_warmup(&state);

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

- if (test2[i].result != prandom_u32_state(&state))
+ if (test2[i].result != result)
errors++;

runs++;
--
2.0.0


\
 
 \ /
  Last update: 2014-06-07 11:01    [W:0.143 / U:0.224 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site