Skip to content

Commit

Permalink
random32: use msecs_to_jiffies for reseed timer
Browse files Browse the repository at this point in the history
Use msecs_to_jiffies, for these calculations as different HZ
considerations are taken into account for conversion of the timer
shot, and also it makes the code more readable.

Signed-off-by: Daniel Borkmann <[email protected]>
Signed-off-by: Hannes Frederic Sowa <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
Daniel Borkmann authored and davem330 committed Nov 14, 2013
1 parent 66b2514 commit 0125737
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/random32.c
Original file line number Diff line number Diff line change
Expand Up @@ -214,18 +214,22 @@ static DEFINE_TIMER(seed_timer, __prandom_timer, 0, 0);
static void __prandom_timer(unsigned long dontcare)
{
u32 entropy;
unsigned long expires;

get_random_bytes(&entropy, sizeof(entropy));
prandom_seed(entropy);

/* reseed every ~60 seconds, in [40 .. 80) interval with slack */
seed_timer.expires = jiffies + (40 * HZ + (prandom_u32() % (40 * HZ)));
expires = 40 + (prandom_u32() % 40);
seed_timer.expires = jiffies + msecs_to_jiffies(expires * MSEC_PER_SEC);

add_timer(&seed_timer);
}

static void __init __prandom_start_seed_timer(void)
{
set_timer_slack(&seed_timer, HZ);
seed_timer.expires = jiffies + 40 * HZ;
seed_timer.expires = jiffies + msecs_to_jiffies(40 * MSEC_PER_SEC);
add_timer(&seed_timer);
}

Expand Down

0 comments on commit 0125737

Please sign in to comment.