Skip to content

Commit 7a22215

Browse files
committed
Merge branch 'x86-rdrand-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
* 'x86-rdrand-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: random: Use arch_get_random_int instead of cycle counter if avail
2 parents 2c364fa + cf833d0 commit 7a22215

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

drivers/char/random.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -624,8 +624,8 @@ static struct timer_rand_state input_timer_state;
624624
static void add_timer_randomness(struct timer_rand_state *state, unsigned num)
625625
{
626626
struct {
627-
cycles_t cycles;
628627
long jiffies;
628+
unsigned cycles;
629629
unsigned num;
630630
} sample;
631631
long delta, delta2, delta3;
@@ -637,7 +637,11 @@ static void add_timer_randomness(struct timer_rand_state *state, unsigned num)
637637
goto out;
638638

639639
sample.jiffies = jiffies;
640-
sample.cycles = get_cycles();
640+
641+
/* Use arch random value, fall back to cycles */
642+
if (!arch_get_random_int(&sample.cycles))
643+
sample.cycles = get_cycles();
644+
641645
sample.num = num;
642646
mix_pool_bytes(&input_pool, &sample, sizeof(sample));
643647

0 commit comments

Comments
 (0)